Skip to main content

max / goingson

3.6 KB · 114 lines History Blame Raw
1 //! Plugin system error types.
2
3 use thiserror::Error;
4
5 /// Plugin system errors.
6 #[derive(Debug, Error)]
7 pub enum PluginError {
8 /// Plugin manifest is invalid or missing required fields.
9 #[error("Invalid manifest: {0}")]
10 InvalidManifest(String),
11
12 /// Plugin script has syntax errors.
13 #[error("Script error in {plugin}: {message}")]
14 ScriptError { plugin: String, message: String },
15
16 /// Plugin execution hit safety limits.
17 #[error("Safety limit exceeded in {plugin}: {message}")]
18 SafetyLimitExceeded { plugin: String, message: String },
19
20 /// Plugin is missing required function.
21 #[error("Plugin {plugin} missing required function: {function}")]
22 MissingFunction { plugin: String, function: String },
23
24 /// Plugin returned invalid data.
25 #[error("Invalid return value from {plugin}: {message}")]
26 InvalidReturn { plugin: String, message: String },
27
28 /// File I/O error.
29 #[error("File error: {0}")]
30 FileError(String),
31
32 /// Plugin directory not found.
33 #[error("Plugin directory not found: {0}")]
34 DirectoryNotFound(String),
35
36 /// Plugin not found by ID.
37 #[error("Plugin not found: {0}")]
38 PluginNotFound(String),
39
40 /// Capability not granted.
41 #[error("Permission denied: {plugin} lacks capability {capability}")]
42 PermissionDenied { plugin: String, capability: String },
43
44 /// Plugin reload requested capabilities beyond what was previously approved.
45 #[error("Capability escalation in {plugin}: new capabilities requested: {details}")]
46 CapabilityEscalation { plugin: String, details: String },
47
48 /// Import parse error.
49 #[error("Import parse error: {0}")]
50 ImportError(String),
51
52 /// Core error wrapper.
53 #[error("Core error: {0}")]
54 Core(#[from] goingson_core::CoreError),
55 }
56
57 impl PluginError {
58 /// Creates a script error for a specific plugin.
59 #[tracing::instrument(skip_all)]
60 pub fn script(plugin: impl Into<String>, message: impl Into<String>) -> Self {
61 PluginError::ScriptError {
62 plugin: plugin.into(),
63 message: message.into(),
64 }
65 }
66
67 /// Creates a safety limit error.
68 #[tracing::instrument(skip_all)]
69 pub fn safety_limit(plugin: impl Into<String>, message: impl Into<String>) -> Self {
70 PluginError::SafetyLimitExceeded {
71 plugin: plugin.into(),
72 message: message.into(),
73 }
74 }
75
76 /// Creates a missing function error.
77 #[tracing::instrument(skip_all)]
78 pub fn missing_function(plugin: impl Into<String>, function: impl Into<String>) -> Self {
79 PluginError::MissingFunction {
80 plugin: plugin.into(),
81 function: function.into(),
82 }
83 }
84
85 /// Creates an invalid return value error.
86 #[tracing::instrument(skip_all)]
87 pub fn invalid_return(plugin: impl Into<String>, message: impl Into<String>) -> Self {
88 PluginError::InvalidReturn {
89 plugin: plugin.into(),
90 message: message.into(),
91 }
92 }
93
94 /// Creates a permission denied error.
95 #[tracing::instrument(skip_all)]
96 pub fn permission_denied(plugin: impl Into<String>, capability: impl Into<String>) -> Self {
97 PluginError::PermissionDenied {
98 plugin: plugin.into(),
99 capability: capability.into(),
100 }
101 }
102
103 /// Creates a capability escalation error.
104 pub fn capability_escalation(plugin: impl Into<String>, details: impl Into<String>) -> Self {
105 PluginError::CapabilityEscalation {
106 plugin: plugin.into(),
107 details: details.into(),
108 }
109 }
110 }
111
112 /// Result type for plugin operations.
113 pub type Result<T> = std::result::Result<T, PluginError>;
114