| 1 |
|
| 2 |
|
| 3 |
use thiserror::Error; |
| 4 |
|
| 5 |
|
| 6 |
#[derive(Debug, Error)] |
| 7 |
pub enum PluginError { |
| 8 |
|
| 9 |
#[error("Invalid manifest: {0}")] |
| 10 |
InvalidManifest(String), |
| 11 |
|
| 12 |
|
| 13 |
#[error("Script error in {plugin}: {message}")] |
| 14 |
ScriptError { plugin: String, message: String }, |
| 15 |
|
| 16 |
|
| 17 |
#[error("Safety limit exceeded in {plugin}: {message}")] |
| 18 |
SafetyLimitExceeded { plugin: String, message: String }, |
| 19 |
|
| 20 |
|
| 21 |
#[error("Plugin {plugin} missing required function: {function}")] |
| 22 |
MissingFunction { plugin: String, function: String }, |
| 23 |
|
| 24 |
|
| 25 |
#[error("Invalid return value from {plugin}: {message}")] |
| 26 |
InvalidReturn { plugin: String, message: String }, |
| 27 |
|
| 28 |
|
| 29 |
#[error("File error: {0}")] |
| 30 |
FileError(String), |
| 31 |
|
| 32 |
|
| 33 |
#[error("Plugin directory not found: {0}")] |
| 34 |
DirectoryNotFound(String), |
| 35 |
|
| 36 |
|
| 37 |
#[error("Plugin not found: {0}")] |
| 38 |
PluginNotFound(String), |
| 39 |
|
| 40 |
|
| 41 |
#[error("Permission denied: {plugin} lacks capability {capability}")] |
| 42 |
PermissionDenied { plugin: String, capability: String }, |
| 43 |
|
| 44 |
|
| 45 |
#[error("Capability escalation in {plugin}: new capabilities requested: {details}")] |
| 46 |
CapabilityEscalation { plugin: String, details: String }, |
| 47 |
|
| 48 |
|
| 49 |
#[error("Import parse error: {0}")] |
| 50 |
ImportError(String), |
| 51 |
|
| 52 |
|
| 53 |
#[error("Core error: {0}")] |
| 54 |
Core(#[from] goingson_core::CoreError), |
| 55 |
} |
| 56 |
|
| 57 |
impl PluginError { |
| 58 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 113 |
pub type Result<T> = std::result::Result<T, PluginError>; |
| 114 |
|