Skip to main content

agents_skills/
error.rs

1//! Unified error types.
2
3/// Unified error type for the whole crate.
4#[derive(Debug, thiserror::Error)]
5pub enum SkillsError {
6    /// A user-facing plain error message.
7    #[error("{0}")]
8    Message(String),
9    /// One or more invalid agent names (comma-separated).
10    #[error("invalid agents: {0}")]
11    InvalidAgents(String),
12    /// I/O error.
13    #[error(transparent)]
14    Io(#[from] std::io::Error),
15    /// JSON (de)serialization error.
16    #[error(transparent)]
17    Json(#[from] serde_json::Error),
18    /// YAML (de)serialization error.
19    #[error(transparent)]
20    Yaml(#[from] serde_yaml::Error),
21    /// git (libgit2) error.
22    #[error(transparent)]
23    Git(#[from] git2::Error),
24    /// HTTP request error.
25    #[error(transparent)]
26    Http(Box<ureq::Error>),
27    /// Zip archive error.
28    #[error(transparent)]
29    Zip(#[from] zip::result::ZipError),
30}
31
32/// Project-wide unified `Result` alias.
33pub type Result<T> = std::result::Result<T, SkillsError>;
34
35/// Semantic alias for library consumers.
36pub type Error = SkillsError;
37
38impl SkillsError {
39    /// Construct a plain-message error.
40    pub fn msg(msg: impl Into<String>) -> Self {
41        SkillsError::Message(msg.into())
42    }
43}
44
45impl From<ureq::Error> for SkillsError {
46    fn from(e: ureq::Error) -> Self {
47        SkillsError::Http(Box::new(e))
48    }
49}