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("wire format mismatch: plugin uses {got}, host expects {expected}. Ensure both are built with the same profile.")]
41    WireFormatMismatch {
42        got: fidius_core::descriptor::WireFormat,
43        expected: fidius_core::descriptor::WireFormat,
44    },
45
46    #[error("buffer strategy mismatch: plugin uses {got}, host expects {expected}")]
47    BufferStrategyMismatch {
48        got: fidius_core::descriptor::BufferStrategyKind,
49        expected: fidius_core::descriptor::BufferStrategyKind,
50    },
51
52    #[error("architecture mismatch: expected {expected}, got {got}")]
53    ArchitectureMismatch { expected: String, got: String },
54
55    #[error("unknown wire format discriminant: {value}")]
56    UnknownWireFormat { value: u8 },
57
58    #[error("unknown buffer strategy discriminant: {value}")]
59    UnknownBufferStrategy { value: u8 },
60
61    #[error("signature verification failed for {path}")]
62    SignatureInvalid { path: String },
63
64    #[error("signature required but no .sig file found for {path}")]
65    SignatureRequired { path: String },
66
67    #[error("plugin '{name}' not found")]
68    PluginNotFound { name: String },
69
70    #[error("libloading error: {0}")]
71    LibLoading(#[from] libloading::Error),
72
73    #[error("io error: {0}")]
74    Io(#[from] std::io::Error),
75}
76
77/// Errors that can occur when calling a plugin method.
78#[derive(Debug, thiserror::Error)]
79pub enum CallError {
80    #[error("serialization error: {0}")]
81    Serialization(String),
82
83    #[error("deserialization error: {0}")]
84    Deserialization(String),
85
86    #[error("plugin error: {0}")]
87    Plugin(PluginError),
88
89    #[error("plugin panicked: {0}")]
90    Panic(String),
91
92    #[error("buffer too small")]
93    BufferTooSmall,
94
95    #[error("method not implemented (capability bit {bit} not set)")]
96    NotImplemented { bit: u32 },
97
98    #[error("unknown FFI status code: {code}")]
99    UnknownStatus { code: i32 },
100}