plux_lua_manager/error.rs
1//! Error handling for the Plux Lua Manager.
2//!
3//! This module defines the error types used throughout the Plux Lua Manager.
4//! It provides structured error handling for different components of the plugin system.
5//!
6//! # Error Types
7//!
8//! - [`ConfigError`]: Errors related to plugin configuration
9//! - [`PluginError`]: Errors specific to plugin operations
10//! - [`ManagerError`]: Top-level error type that can represent any error in the manager
11
12use mlua::Error as LuaError;
13use thiserror::Error;
14
15/// Errors that can occur when working with plugin configuration.
16///
17/// This enum represents various error conditions that can occur when
18/// loading or parsing plugin configuration files.
19#[derive(Error, Debug)]
20pub enum ConfigError {
21 /// The configuration file was not found in the expected location.
22 #[error("Config file not found")]
23 NotFound,
24
25 /// The configuration file could not be parsed as valid TOML.
26 #[error("Invalid config format: {0}")]
27 InvalidFormat(#[from] toml::de::Error),
28
29 /// An I/O error occurred while reading the configuration file.
30 #[error("IO error: {0}")]
31 Io(#[from] std::io::Error),
32}
33
34/// Errors that can occur during plugin operations.
35///
36/// This enum represents various error conditions that can occur when
37/// loading, initializing, or executing plugins.
38#[derive(Error, Debug)]
39pub enum PluginError {
40 /// The plugin source code could not be loaded or compiled.
41 #[error("Source error: {0}")]
42 SourceError(String),
43
44 /// An I/O error occurred while working with plugin files.
45 #[error("IO error: {0}")]
46 IoError(#[from] std::io::Error),
47
48 /// An error occurred while registering plugin functions.
49 #[error("Plugin register function error: {0}")]
50 RegisterFunctionError(#[from] plux_rs::utils::PluginRegisterFunctionError),
51}
52
53/// The top-level error type for the Lua manager.
54///
55/// This enum represents all possible errors that can occur when working
56/// with the Lua manager. It can be converted from more specific error types.
57#[derive(Error, Debug)]
58pub enum ManagerError {
59 /// An error originating from the Lua runtime.
60 #[error("Lua error: {0}")]
61 Lua(#[from] LuaError),
62
63 /// An error related to plugin configuration.
64 #[error("Config error: {0}")]
65 Config(#[from] ConfigError),
66
67 /// An error related to plugin operations.
68 #[error("Plugin error: {0}")]
69 Plugin(#[from] PluginError),
70}