skilllite_core/error.rs
1//! Structured error types for public API boundaries.
2//!
3//! Use thiserror for APIs consumed by other crates, enabling:
4//! - Precise error matching (e.g. retry on NotFound, abort on PathEscape)
5//! - Clear error messages without losing context
6//! - Automatic conversion to anyhow via `?` in caller code
7
8use thiserror::Error;
9
10// ── Path validation errors ───────────────────────────────────────────────────
11
12/// Errors from path validation operations.
13///
14/// Used by `get_allowed_root`, `validate_path_under_root`, `validate_skill_path`.
15#[derive(Debug, Error)]
16pub enum PathValidationError {
17 /// The configured SKILLLITE_SKILLS_ROOT (or cwd) could not be resolved.
18 #[error("Invalid SKILLLITE_SKILLS_ROOT: {0}")]
19 InvalidRoot(#[from] std::io::Error),
20
21 /// Path does not exist.
22 #[error("{path_type} does not exist: {path}")]
23 NotFound {
24 /// Human-readable type (e.g. "Skill path", "Script path")
25 path_type: String,
26 /// The invalid path
27 path: String,
28 },
29
30 /// Path escapes the allowed root (potential path traversal).
31 #[error("{path_type} escapes allowed root: {path}")]
32 PathEscape {
33 /// Human-readable type
34 path_type: String,
35 /// The escaping path
36 path: String,
37 },
38}