acp/
error.rs

1//! @acp:module "Error Types"
2//! @acp:summary "Comprehensive error handling for ACP operations"
3//! @acp:domain cli
4//! @acp:layer utility
5
6use thiserror::Error;
7
8/// @acp:summary "Result type alias for ACP operations"
9pub type Result<T> = std::result::Result<T, AcpError>;
10
11/// @acp:summary "Comprehensive error types for ACP operations"
12/// @acp:lock normal
13#[derive(Error, Debug)]
14pub enum AcpError {
15    /// IO operation failed
16    #[error("IO error: {0}")]
17    Io(#[from] std::io::Error),
18
19    /// JSON serialization/deserialization failed
20    #[error("JSON error: {0}")]
21    Json(#[from] serde_json::Error),
22
23    /// Source code parsing failed
24    #[error("Parse error: {message}")]
25    Parse {
26        message: String,
27        file: Option<String>,
28        line: Option<usize>,
29    },
30
31    /// File not found
32    #[error("File not found: {0}")]
33    FileNotFound(String),
34
35    /// Invalid configuration
36    #[error("Invalid configuration: {0}")]
37    Config(String),
38
39    /// Variable reference not found
40    #[error("Variable not found: {0}")]
41    VarNotFound(String),
42
43    /// Circular dependency in variable inheritance
44    #[error("Cycle detected in variable inheritance: {0}")]
45    CycleDetected(String),
46
47    /// JSON schema validation failed
48    #[error("Schema validation failed: {0}")]
49    SchemaValidation(String),
50
51    /// Semantic validation failed (constraints that can't be expressed in JSON Schema)
52    #[error("Semantic validation failed: {0}")]
53    SemanticValidation(String),
54
55    /// Language not supported
56    #[error("Unsupported language: {0}")]
57    UnsupportedLanguage(String),
58
59    /// Indexing operation failed
60    #[error("Index error: {0}")]
61    Index(String),
62
63    /// Generic error
64    #[error("{0}")]
65    Other(String),
66}
67
68impl AcpError {
69    /// @acp:summary "Create a parse error without location context"
70    pub fn parse(message: impl Into<String>) -> Self {
71        Self::Parse {
72            message: message.into(),
73            file: None,
74            line: None,
75        }
76    }
77
78    /// @acp:summary "Create a parse error with file and line context"
79    pub fn parse_at(message: impl Into<String>, file: impl Into<String>, line: usize) -> Self {
80        Self::Parse {
81            message: message.into(),
82            file: Some(file.into()),
83            line: Some(line),
84        }
85    }
86}