Skip to main content

fidius_host/
error.rs

1// Copyright 2026 Colliery, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Error types for fidius-host plugin loading and calling.
16
17use fidius_core::PluginError;
18
19/// Errors that can occur when loading a plugin.
20#[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    /// Python loader failed (only produced with the `python` feature on).
68    /// Wraps `fidius_python::PythonLoadError` as a string to keep the
69    /// fidius-host public error enum type-clean across feature gates.
70    #[error("python load failed: {0}")]
71    PythonLoad(String),
72}
73
74/// Errors that can occur when calling a plugin method.
75#[derive(Debug, thiserror::Error)]
76pub enum CallError {
77    #[error("serialization error: {0}")]
78    Serialization(String),
79
80    #[error("deserialization error: {0}")]
81    Deserialization(String),
82
83    #[error("plugin error: {0}")]
84    Plugin(PluginError),
85
86    #[error("plugin panicked: {0}")]
87    Panic(String),
88
89    #[error("buffer too small")]
90    BufferTooSmall,
91
92    /// Optional method is not implemented by this plugin — its capability bit is unset.
93    /// Returned when a method marked `#[optional]` is called on a plugin that chose not
94    /// to implement it. Not returned for out-of-range method indices; see `InvalidMethodIndex`.
95    #[error("method not implemented (capability bit {bit} not set)")]
96    NotImplemented { bit: u32 },
97
98    #[error("invalid method index {index} (plugin has {count} method(s))")]
99    InvalidMethodIndex { index: usize, count: u32 },
100
101    #[error("unknown FFI status code: {code}")]
102    UnknownStatus { code: i32 },
103}