Skip to main content

agent_policy/
error.rs

1// Error types — implemented in Phase 1
2
3use std::path::PathBuf;
4
5/// All errors produced by agent-policy.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// An I/O operation failed.
9    #[error("I/O error reading '{path}': {source}")]
10    Io {
11        path: PathBuf,
12        #[source]
13        source: std::io::Error,
14    },
15
16    /// The YAML file could not be parsed.
17    #[error("YAML parse error: {0}")]
18    Yaml(#[from] serde_yaml::Error),
19
20    /// The policy failed JSON Schema validation.
21    #[error("Policy validation failed:\n{0}")]
22    Schema(String),
23
24    /// A glob pattern in the policy is invalid.
25    #[error("Invalid glob pattern '{pattern}': {source}")]
26    Glob {
27        pattern: String,
28        #[source]
29        source: globset::Error,
30    },
31
32    /// A role name contains invalid characters.
33    #[error("Invalid role name '{name}': use only lowercase letters, digits, and underscores")]
34    InvalidRoleName { name: String },
35
36    /// Template rendering failed.
37    #[error("Render error for target '{target}': {source}")]
38    Render {
39        target: String,
40        #[source]
41        source: minijinja::Error,
42    },
43
44    /// Generated file content differs from the committed file.
45    #[error("Stale generated file: {}", path.display())]
46    CheckFailed { path: PathBuf },
47
48    /// The outputs list is present but empty.
49    #[error(
50        "No outputs are enabled. Add at least one target ID to `outputs` (e.g. `outputs: [agents-md]`)."
51    )]
52    NoOutputs,
53
54    /// An unrecognized target ID was specified in outputs.
55    #[error(
56        "Unknown output target '{id}'. Run `agent-policy list-targets` to see all supported targets."
57    )]
58    UnknownTarget { id: String },
59}
60
61/// Convenience alias.
62pub type Result<T> = std::result::Result<T, Error>;