Skip to main content

agentic_codebase/types/
error.rs

1//! Error types for the AgenticCodebase system.
2//!
3//! All errors are typed using `thiserror` and propagated through `AcbResult`.
4
5use std::path::PathBuf;
6use thiserror::Error;
7
8/// All error types that can occur in the AgenticCodebase system.
9#[derive(Error, Debug)]
10pub enum AcbError {
11    /// Invalid magic bytes in file header.
12    #[error("Invalid magic bytes in file header")]
13    InvalidMagic,
14
15    /// Unsupported format version.
16    #[error("Unsupported format version: {0}")]
17    UnsupportedVersion(u32),
18
19    /// Code unit ID not found.
20    #[error("Code unit ID {0} not found")]
21    UnitNotFound(u64),
22
23    /// Edge references an invalid code unit.
24    #[error("Edge references invalid code unit: {0}")]
25    InvalidEdgeTarget(u64),
26
27    /// Self-edges are not allowed.
28    #[error("Self-edge not allowed on unit {0}")]
29    SelfEdge(u64),
30
31    /// Symbol name exceeds maximum length.
32    #[error("Symbol name too long: {len} > {max}")]
33    NameTooLong {
34        /// Actual length.
35        len: usize,
36        /// Maximum allowed.
37        max: usize,
38    },
39
40    /// Path exceeds maximum length.
41    #[error("Path too long: {len} > {max}")]
42    PathTooLong {
43        /// Actual length.
44        len: usize,
45        /// Maximum allowed.
46        max: usize,
47    },
48
49    /// Feature vector dimension does not match expected dimension.
50    #[error("Feature vector dimension mismatch: expected {expected}, got {got}")]
51    DimensionMismatch {
52        /// Expected dimension.
53        expected: usize,
54        /// Actual dimension.
55        got: usize,
56    },
57
58    /// Too many edges for a single code unit.
59    #[error("Maximum edges per unit exceeded: {0}")]
60    TooManyEdges(u32),
61
62    /// Path does not exist on disk.
63    #[error("Path not found: {0}")]
64    PathNotFound(PathBuf),
65
66    /// Language is not supported.
67    #[error("Unsupported language: {0}")]
68    UnsupportedLanguage(String),
69
70    /// A parsing error occurred.
71    #[error("Parse error in {path}: {message}")]
72    ParseError {
73        /// File that caused the error.
74        path: PathBuf,
75        /// Description of the parse failure.
76        message: String,
77    },
78
79    /// A semantic analysis error occurred.
80    #[error("Semantic error: {0}")]
81    SemanticError(String),
82
83    /// A git-related error occurred.
84    #[error("Git error: {0}")]
85    GitError(String),
86
87    /// An I/O error occurred.
88    #[error("IO error: {0}")]
89    Io(#[from] std::io::Error),
90
91    /// A compression or decompression error occurred.
92    #[error("Compression error: {0}")]
93    Compression(String),
94
95    /// The file is empty or truncated.
96    #[error("File is empty or truncated")]
97    Truncated,
98
99    /// Corrupt data detected at the given offset.
100    #[error("Corrupt data at offset {0}")]
101    Corrupt(u64),
102
103    /// A query execution error.
104    #[error("Query error: {0}")]
105    QueryError(String),
106
107    /// A collective sync error.
108    #[error("Collective sync error: {0}")]
109    CollectiveError(String),
110
111    /// Duplicate edge detected.
112    #[error("Duplicate edge from {0} to {1}")]
113    DuplicateEdge(u64, u64),
114}
115
116/// Convenience result type for AgenticCodebase operations.
117pub type AcbResult<T> = Result<T, AcbError>;