Skip to main content

palladium_plugin/
error.rs

1use std::fmt;
2
3/// Errors that can occur during plugin loading, unloading, or actor creation.
4#[derive(Debug, Clone, PartialEq)]
5pub enum PluginError {
6    /// The plugin's reported ABI version does not match the engine's.
7    AbiMismatch { expected: u32, found: u32 },
8    /// The plugin file could not be opened or read.
9    LoadFailed(String),
10    /// `pd_plugin_init` returned a null pointer or the WASM equivalent failed.
11    InitFailed,
12    /// No plugin or actor type is registered under the given name.
13    UnknownType(String),
14    /// The plugin requested a namespace its manifest does not allow.
15    NamespaceViolation,
16    /// A WASM-specific error (compilation, instantiation, or trap).
17    WasmError(String),
18}
19
20impl fmt::Display for PluginError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Self::AbiMismatch { expected, found } => write!(
24                f,
25                "ABI mismatch: engine expects version {expected}, plugin reports {found}"
26            ),
27            Self::LoadFailed(msg) => write!(f, "plugin load failed: {msg}"),
28            Self::InitFailed => write!(f, "pd_plugin_init returned null or failed"),
29            Self::UnknownType(name) => write!(f, "unknown plugin or actor type: '{name}'"),
30            Self::NamespaceViolation => {
31                write!(
32                    f,
33                    "plugin requested a namespace not permitted by its manifest"
34                )
35            }
36            Self::WasmError(msg) => write!(f, "WASM error: {msg}"),
37        }
38    }
39}
40
41impl std::error::Error for PluginError {}