mockforge_plugin_core/
error.rs1pub type Result<T> = std::result::Result<T, PluginError>;
5
6#[derive(Debug, thiserror::Error)]
8pub enum PluginError {
9 #[error("Plugin loading error: {message}")]
11 LoadError {
12 message: String,
14 },
15
16 #[error("Plugin execution error: {message}")]
18 ExecutionError {
19 message: String,
21 },
22
23 #[error("Security violation: {violation}")]
25 SecurityViolation {
26 violation: String,
28 },
29
30 #[error("Resource limit exceeded: {resource} limit={limit}, used={used}")]
32 ResourceLimitExceeded {
33 resource: String,
35 limit: String,
37 used: String,
39 },
40
41 #[error("Invalid plugin configuration: {field} - {message}")]
43 InvalidConfiguration {
44 field: String,
46 message: String,
48 },
49
50 #[error("Plugin compatibility error: {reason}")]
52 CompatibilityError {
53 reason: String,
55 },
56
57 #[error("Plugin communication error: {message}")]
59 CommunicationError {
60 message: String,
62 },
63
64 #[error("Plugin execution timeout: {timeout_ms}ms exceeded")]
66 TimeoutError {
67 timeout_ms: u64,
69 },
70
71 #[error("WebAssembly runtime error: {message}")]
73 WasmError {
74 message: String,
76 },
77
78 #[error("Invalid plugin manifest: {message}")]
80 InvalidManifest {
81 message: String,
83 },
84
85 #[error("Plugin dependency error: {dependency} - {message}")]
87 DependencyError {
88 dependency: String,
90 message: String,
92 },
93
94 #[error("Plugin system error: {message}")]
96 SystemError {
97 message: String,
99 },
100}
101
102impl PluginError {
103 pub fn load<S: Into<String>>(message: S) -> Self {
105 Self::LoadError {
106 message: message.into(),
107 }
108 }
109
110 pub fn execution<S: Into<String>>(message: S) -> Self {
112 Self::ExecutionError {
113 message: message.into(),
114 }
115 }
116
117 pub fn security<S: Into<String>>(violation: S) -> Self {
119 Self::SecurityViolation {
120 violation: violation.into(),
121 }
122 }
123
124 pub fn resource_limit<S: Into<String>>(resource: S, limit: S, used: S) -> Self {
126 Self::ResourceLimitExceeded {
127 resource: resource.into(),
128 limit: limit.into(),
129 used: used.into(),
130 }
131 }
132
133 pub fn config<S: Into<String>>(field: S, message: S) -> Self {
135 Self::InvalidConfiguration {
136 field: field.into(),
137 message: message.into(),
138 }
139 }
140
141 pub fn compatibility<S: Into<String>>(reason: S) -> Self {
143 Self::CompatibilityError {
144 reason: reason.into(),
145 }
146 }
147
148 pub fn communication<S: Into<String>>(message: S) -> Self {
150 Self::CommunicationError {
151 message: message.into(),
152 }
153 }
154
155 pub fn timeout(timeout_ms: u64) -> Self {
157 Self::TimeoutError { timeout_ms }
158 }
159
160 pub fn wasm<S: Into<String>>(message: S) -> Self {
162 Self::WasmError {
163 message: message.into(),
164 }
165 }
166
167 pub fn manifest<S: Into<String>>(message: S) -> Self {
169 Self::InvalidManifest {
170 message: message.into(),
171 }
172 }
173
174 pub fn dependency<S: Into<String>>(dependency: S, message: S) -> Self {
176 Self::DependencyError {
177 dependency: dependency.into(),
178 message: message.into(),
179 }
180 }
181
182 pub fn system<S: Into<String>>(message: S) -> Self {
184 Self::SystemError {
185 message: message.into(),
186 }
187 }
188
189 pub fn is_security_error(&self) -> bool {
191 matches!(self, PluginError::SecurityViolation { .. })
192 }
193
194 pub fn is_resource_error(&self) -> bool {
196 matches!(self, PluginError::ResourceLimitExceeded { .. })
197 }
198
199 pub fn is_timeout_error(&self) -> bool {
201 matches!(self, PluginError::TimeoutError { .. })
202 }
203}
204
205#[cfg(test)]
206mod tests {
207
208 #[test]
209 fn test_module_compiles() {
210 }
212}