use fidius_core::PluginError;
#[derive(Debug, thiserror::Error)]
pub enum LoadError {
#[error("library not found: {path}")]
LibraryNotFound { path: String },
#[error("symbol 'fidius_get_registry' not found in {path}")]
SymbolNotFound { path: String },
#[error("invalid magic bytes (expected FIDIUS\\0\\0)")]
InvalidMagic,
#[error("incompatible registry version: got {got}, expected {expected}")]
IncompatibleRegistryVersion { got: u32, expected: u32 },
#[error("incompatible ABI version: got {got}, expected {expected}")]
IncompatibleAbiVersion { got: u32, expected: u32 },
#[error("interface hash mismatch: got {got:#x}, expected {expected:#x}")]
InterfaceHashMismatch { got: u64, expected: u64 },
#[error("buffer strategy mismatch: plugin uses {got}, host expects {expected}")]
BufferStrategyMismatch {
got: fidius_core::descriptor::BufferStrategyKind,
expected: fidius_core::descriptor::BufferStrategyKind,
},
#[error("architecture mismatch: expected {expected}, got {got}")]
ArchitectureMismatch { expected: String, got: String },
#[error("unknown buffer strategy discriminant: {value}")]
UnknownBufferStrategy { value: u8 },
#[error("signature verification failed for {path}")]
SignatureInvalid { path: String },
#[error("signature required but no .sig file found for {path}")]
SignatureRequired { path: String },
#[error("plugin '{name}' not found")]
PluginNotFound { name: String },
#[error("libloading error: {0}")]
LibLoading(#[from] libloading::Error),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("python load failed: {0}")]
PythonLoad(String),
#[error("wasm load failed: {0}")]
WasmLoad(String),
}
#[derive(Debug, thiserror::Error)]
pub enum CallError {
#[error("serialization error: {0}")]
Serialization(String),
#[error("deserialization error: {0}")]
Deserialization(String),
#[error("plugin error: {0}")]
Plugin(PluginError),
#[error("plugin panicked: {0}")]
Panic(String),
#[error("buffer too small")]
BufferTooSmall,
#[error("method not implemented (capability bit {bit} not set)")]
NotImplemented { bit: u32 },
#[error("invalid method index {index} (plugin has {count} method(s))")]
InvalidMethodIndex { index: usize, count: u32 },
#[error("unknown FFI status code: {code}")]
UnknownStatus { code: i32 },
#[error(
"wire-mode mismatch on method '{method}': declared wire_raw={declared}, dispatcher used wire_raw={attempted}"
)]
WireModeMismatch {
method: String,
declared: bool,
attempted: bool,
},
#[error("{runtime} backend error: {message}")]
Backend { runtime: String, message: String },
}
#[cfg(feature = "python")]
impl From<fidius_python::PythonCallError> for CallError {
fn from(e: fidius_python::PythonCallError) -> Self {
use fidius_python::PythonCallError as P;
match e {
P::InvalidMethodIndex { index, count } => CallError::InvalidMethodIndex {
index,
count: count as u32,
},
P::WireModeMismatch {
method,
declared,
attempted,
} => CallError::WireModeMismatch {
method: method.to_string(),
declared,
attempted,
},
P::InputDecode(msg) => CallError::Deserialization(msg),
P::OutputEncode(msg) => CallError::Serialization(msg),
P::Plugin(err) => CallError::Plugin(err),
}
}
}