use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum SkillError {
#[error("Skill file not found: {0}")]
FileNotFound(PathBuf),
#[error("Failed to read skill file {path}: {source}")]
ReadError {
path: PathBuf,
source: std::io::Error,
},
#[error("Invalid YAML frontmatter in {path}: {source}")]
InvalidFrontmatter {
path: PathBuf,
source: serde_yaml::Error,
},
#[error("Missing required field '{field}' in {path}")]
MissingField {
field: String,
path: PathBuf,
},
#[error("Invalid skill name '{name}': {reason}")]
InvalidName {
name: String,
reason: String,
},
#[error("Invalid skill description: {0}")]
InvalidDescription(String),
#[error("Skill not found: {0}")]
NotFound(String),
#[error("Failed to load instructions for skill '{skill}': {source}")]
LoadInstructionsError {
skill: String,
source: std::io::Error,
},
#[error("Failed to list resources for skill '{skill}': {source}")]
ListResourcesError {
skill: String,
source: std::io::Error,
},
#[error("Invalid path: directory traversal detected in {0}")]
DirectoryTraversal(PathBuf),
#[error("Skill directory not found: {0}")]
DirectoryNotFound(PathBuf),
}
impl SkillError {
pub fn read_error(path: PathBuf, source: std::io::Error) -> Self {
Self::ReadError { path, source }
}
pub fn invalid_frontmatter(path: PathBuf, source: serde_yaml::Error) -> Self {
Self::InvalidFrontmatter { path, source }
}
pub fn missing_field(field: impl Into<String>, path: PathBuf) -> Self {
Self::MissingField {
field: field.into(),
path,
}
}
pub fn invalid_name(name: impl Into<String>, reason: impl Into<String>) -> Self {
Self::InvalidName {
name: name.into(),
reason: reason.into(),
}
}
pub fn load_instructions_error(skill: impl Into<String>, source: std::io::Error) -> Self {
Self::LoadInstructionsError {
skill: skill.into(),
source,
}
}
pub fn list_resources_error(skill: impl Into<String>, source: std::io::Error) -> Self {
Self::ListResourcesError {
skill: skill.into(),
source,
}
}
}