Skip to main content

adrs_core/
error.rs

1//! Error types for adrs-core.
2
3use std::path::PathBuf;
4
5/// Result type alias using the library's error type.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur when working with ADRs.
9#[derive(Debug, thiserror::Error)]
10pub enum Error {
11    /// The ADR directory was not found.
12    #[error("ADR directory not found. Run 'adrs init' to create one.")]
13    AdrDirNotFound,
14
15    /// The ADR directory already exists.
16    #[error("ADR directory already exists: {0}")]
17    AdrDirExists(PathBuf),
18
19    /// An ADR was not found.
20    #[error("ADR not found: {0}")]
21    AdrNotFound(String),
22
23    /// Multiple ADRs matched a query.
24    #[error("Multiple ADRs match '{query}': {matches:?}")]
25    AmbiguousAdr {
26        /// The query string that matched more than one ADR.
27        query: String,
28        /// Human-readable identifiers of the ADRs that matched.
29        matches: Vec<String>,
30    },
31
32    /// Invalid ADR number.
33    #[error("Invalid ADR number: {0}")]
34    InvalidNumber(String),
35
36    /// Invalid ADR format (parsing failed).
37    #[error("Invalid ADR format in {path}: {reason}")]
38    InvalidFormat {
39        /// Path to the ADR file that failed to parse.
40        path: PathBuf,
41        /// Why parsing failed.
42        reason: String,
43    },
44
45    /// Missing required field in ADR.
46    #[error("Missing required field '{field}' in {path}")]
47    MissingField {
48        /// Path to the ADR file missing the field.
49        path: PathBuf,
50        /// Name of the required field that was missing.
51        field: String,
52    },
53
54    /// Invalid status value.
55    #[error("Invalid status: {0}")]
56    InvalidStatus(String),
57
58    /// Invalid link format.
59    #[error("Invalid link format: {0}")]
60    InvalidLink(String),
61
62    /// Template not found.
63    #[error("Template not found: {0}")]
64    TemplateNotFound(String),
65
66    /// Template rendering error.
67    #[error("Template error: {0}")]
68    TemplateError(String),
69
70    /// Configuration error.
71    #[error("Configuration error: {0}")]
72    ConfigError(String),
73
74    /// I/O error.
75    #[error("I/O error: {0}")]
76    Io(#[from] std::io::Error),
77
78    /// YAML parsing error.
79    #[error("YAML error: {0}")]
80    Yaml(#[from] serde_yaml_neo::Error),
81
82    /// TOML parsing error.
83    #[error("TOML error: {0}")]
84    Toml(#[from] toml::de::Error),
85}