1use fidius_core::PluginError;
18
19#[derive(Debug, thiserror::Error)]
21pub enum LoadError {
22 #[error("library not found: {path}")]
23 LibraryNotFound { path: String },
24
25 #[error("symbol 'fidius_get_registry' not found in {path}")]
26 SymbolNotFound { path: String },
27
28 #[error("invalid magic bytes (expected FIDIUS\\0\\0)")]
29 InvalidMagic,
30
31 #[error("incompatible registry version: got {got}, expected {expected}")]
32 IncompatibleRegistryVersion { got: u32, expected: u32 },
33
34 #[error("incompatible ABI version: got {got}, expected {expected}")]
35 IncompatibleAbiVersion { got: u32, expected: u32 },
36
37 #[error("interface hash mismatch: got {got:#x}, expected {expected:#x}")]
38 InterfaceHashMismatch { got: u64, expected: u64 },
39
40 #[error("buffer strategy mismatch: plugin uses {got}, host expects {expected}")]
41 BufferStrategyMismatch {
42 got: fidius_core::descriptor::BufferStrategyKind,
43 expected: fidius_core::descriptor::BufferStrategyKind,
44 },
45
46 #[error("architecture mismatch: expected {expected}, got {got}")]
47 ArchitectureMismatch { expected: String, got: String },
48
49 #[error("unknown buffer strategy discriminant: {value}")]
50 UnknownBufferStrategy { value: u8 },
51
52 #[error("signature verification failed for {path}")]
53 SignatureInvalid { path: String },
54
55 #[error("signature required but no .sig file found for {path}")]
56 SignatureRequired { path: String },
57
58 #[error("plugin '{name}' not found")]
59 PluginNotFound { name: String },
60
61 #[error("libloading error: {0}")]
62 LibLoading(#[from] libloading::Error),
63
64 #[error("io error: {0}")]
65 Io(#[from] std::io::Error),
66
67 #[error("python load failed: {0}")]
71 PythonLoad(String),
72
73 #[error("wasm load failed: {0}")]
77 WasmLoad(String),
78}
79
80#[derive(Debug, thiserror::Error)]
82pub enum CallError {
83 #[error("serialization error: {0}")]
84 Serialization(String),
85
86 #[error("deserialization error: {0}")]
87 Deserialization(String),
88
89 #[error("plugin error: {0}")]
90 Plugin(PluginError),
91
92 #[error("plugin panicked: {0}")]
93 Panic(String),
94
95 #[error("buffer too small")]
96 BufferTooSmall,
97
98 #[error("method not implemented (capability bit {bit} not set)")]
102 NotImplemented { bit: u32 },
103
104 #[error("invalid method index {index} (plugin has {count} method(s))")]
105 InvalidMethodIndex { index: usize, count: u32 },
106
107 #[error("unknown FFI status code: {code}")]
108 UnknownStatus { code: i32 },
109
110 #[error(
114 "wire-mode mismatch on method '{method}': declared wire_raw={declared}, dispatcher used wire_raw={attempted}"
115 )]
116 WireModeMismatch {
117 method: String,
118 declared: bool,
119 attempted: bool,
120 },
121
122 #[error("{runtime} backend error: {message}")]
129 Backend { runtime: String, message: String },
130}
131
132#[cfg(feature = "python")]
140impl From<fidius_python::PythonCallError> for CallError {
141 fn from(e: fidius_python::PythonCallError) -> Self {
142 use fidius_python::PythonCallError as P;
143 match e {
144 P::InvalidMethodIndex { index, count } => CallError::InvalidMethodIndex {
145 index,
146 count: count as u32,
147 },
148 P::WireModeMismatch {
149 method,
150 declared,
151 attempted,
152 } => CallError::WireModeMismatch {
153 method: method.to_string(),
154 declared,
155 attempted,
156 },
157 P::InputDecode(msg) => CallError::Deserialization(msg),
158 P::OutputEncode(msg) => CallError::Serialization(msg),
159 P::Plugin(err) => CallError::Plugin(err),
160 }
161 }
162}