nichlink_plugin_host/
error.rs1use std::{fmt, io};
5
6#[derive(Debug)]
9pub enum HostError {
10 InvalidArtifact(String),
13 InvalidOperation(String),
16 Abi(String),
19 Limit(String),
22 Process(String),
25 Timeout,
28 Health(String),
31 Slot(String),
34 Policy(String),
37 Contract(String),
40 State(String),
43 Registry(String),
46 Io(io::Error),
49}
50
51impl fmt::Display for HostError {
52 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
53 match self {
54 Self::InvalidArtifact(message) => {
55 write!(formatter, "invalid plugin artifact: {message}")
56 }
57 Self::InvalidOperation(message) => {
58 write!(formatter, "invalid plugin operation: {message}")
59 }
60 Self::Abi(message) => write!(formatter, "plugin ABI error: {message}"),
61 Self::Limit(message) => write!(formatter, "plugin limit exceeded: {message}"),
62 Self::Process(message) => write!(formatter, "plugin process failed: {message}"),
63 Self::Timeout => formatter.write_str("plugin call timed out"),
64 Self::Health(message) => write!(formatter, "plugin health check failed: {message}"),
65 Self::Slot(message) => write!(formatter, "plugin slot error: {message}"),
66 Self::Policy(message) => {
67 write!(formatter, "plugin policy rejected artifact: {message}")
68 }
69 Self::Contract(message) => write!(formatter, "plugin contract mismatch: {message}"),
70 Self::State(message) => write!(formatter, "plugin host state failed: {message}"),
71 Self::Registry(message) => write!(formatter, "registry graft failed: {message}"),
72 Self::Io(error) => write!(formatter, "plugin I/O failed: {error}"),
73 }
74 }
75}
76
77impl std::error::Error for HostError {
78 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
79 match self {
80 Self::Io(error) => Some(error),
81 _ => None,
82 }
83 }
84}
85
86impl From<io::Error> for HostError {
87 fn from(error: io::Error) -> Self {
88 Self::Io(error)
89 }
90}