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 { query: String, matches: Vec<String> },
26
27    /// Invalid ADR number.
28    #[error("Invalid ADR number: {0}")]
29    InvalidNumber(String),
30
31    /// Invalid ADR format (parsing failed).
32    #[error("Invalid ADR format in {path}: {reason}")]
33    InvalidFormat { path: PathBuf, reason: String },
34
35    /// Missing required field in ADR.
36    #[error("Missing required field '{field}' in {path}")]
37    MissingField { path: PathBuf, field: String },
38
39    /// Invalid status value.
40    #[error("Invalid status: {0}")]
41    InvalidStatus(String),
42
43    /// Invalid link format.
44    #[error("Invalid link format: {0}")]
45    InvalidLink(String),
46
47    /// Template not found.
48    #[error("Template not found: {0}")]
49    TemplateNotFound(String),
50
51    /// Template rendering error.
52    #[error("Template error: {0}")]
53    TemplateError(String),
54
55    /// Configuration error.
56    #[error("Configuration error: {0}")]
57    ConfigError(String),
58
59    /// I/O error.
60    #[error("I/O error: {0}")]
61    Io(#[from] std::io::Error),
62
63    /// YAML parsing error.
64    #[error("YAML error: {0}")]
65    Yaml(#[from] serde_yaml::Error),
66
67    /// TOML parsing error.
68    #[error("TOML error: {0}")]
69    Toml(#[from] toml::de::Error),
70}