Skip to main content

xz_skill_core/
error.rs

1use std::fmt::Debug;
2
3use crate::types::skill::SkillPermission;
4
5/// Skill system errors
6#[derive(Debug, thiserror::Error)]
7pub enum SkillError {
8    /// The requested skill was not found.
9    #[error("Skill not found: {0}")]
10    NotFound(String),
11
12    /// Execution exceeded the configured timeout.
13    #[error("Execution timed out ({0}ms)")]
14    Timeout(u64),
15
16    /// The operation was denied due to insufficient permissions.
17    #[error("Insufficient permissions: requires {required:?}")]
18    PermissionDenied {
19        /// The permissions that would be required.
20        required: Vec<SkillPermission>,
21    },
22
23    /// A tool failed during execution.
24    #[error("Tool execution failed: {0}")]
25    ToolExecution(String),
26
27    /// An error occurred in the WASM runtime.
28    #[error("WASM error: {0}")]
29    Wasm(String),
30
31    /// Configuration validation failed.
32    #[error("Configuration validation failed: {0}")]
33    ConfigValidation(String),
34
35    /// The skill requires a newer agent version.
36    #[error("Version mismatch: skill requires >= {required}")]
37    VersionMismatch {
38        /// The minimum required version.
39        required: String,
40    },
41
42    /// A preflight check failed before execution.
43    #[error("Preflight check failed: {0}")]
44    PreflightFailed(String),
45
46    /// The skill is disabled and cannot be used.
47    #[error("Skill is disabled: {0}")]
48    Disabled(String),
49
50    /// An I/O error occurred.
51    #[error("IO error: {0}")]
52    Io(#[from] std::io::Error),
53
54    /// Failed to parse YAML content.
55    #[error("YAML parse error: {0}")]
56    Yaml(String),
57
58    /// The WASM binary is invalid.
59    #[error("Invalid WASM binary: {0}")]
60    InvalidWasm(String),
61
62    /// An HTTP request failed.
63    #[error("HTTP error: {0}")]
64    Http(String),
65
66    /// A parse error occurred while reading a skill definition file.
67    #[error("Parse error: {0}")]
68    ParseError(String),
69
70    /// A required field is missing from a skill definition.
71    #[error("Missing required field: {0}")]
72    MissingField(String),
73
74    /// The skill definition file had an invalid format.
75    #[error("Invalid format: {0}")]
76    InvalidFormat(String),
77}
78
79impl SkillError {
80    /// Returns `true` if this error can be retried.
81    ///
82    /// Transient errors (timeout, tool execution failure, HTTP failures,
83    /// IO errors) are retryable. All other errors are permanent and
84    /// should not be retried without intervention.
85    pub fn is_retryable(&self) -> bool {
86        matches!(
87            self,
88            SkillError::Timeout(_)
89                | SkillError::ToolExecution(_)
90                | SkillError::Http(_)
91                | SkillError::Io(_)
92        )
93    }
94}