Skip to main content

argus_core/
error.rs

1use std::path::PathBuf;
2
3/// Errors that can occur across the Argus platform.
4///
5/// Each variant wraps a specific error domain. Library crates use this type
6/// directly; the binary crate converts to `anyhow::Error` at the boundary.
7///
8/// # Examples
9///
10/// ```
11/// use argus_core::ArgusError;
12///
13/// let err = ArgusError::Config("missing API key".into());
14/// assert!(err.to_string().contains("missing API key"));
15/// ```
16#[derive(Debug, thiserror::Error)]
17pub enum ArgusError {
18    /// Filesystem I/O failure.
19    #[error("IO error: {0}")]
20    Io(#[from] std::io::Error),
21
22    /// Invalid or missing configuration.
23    #[error("configuration error: {0}")]
24    Config(String),
25
26    /// Git operation failure.
27    #[error("git error: {0}")]
28    Git(String),
29
30    /// Source code parsing failure.
31    #[error("parse error: {0}")]
32    Parse(String),
33
34    /// LLM API or response error.
35    #[error("LLM error: {0}")]
36    Llm(String),
37
38    /// JSON serialization / deserialization failure.
39    #[error("serialization error: {0}")]
40    Serialization(#[from] serde_json::Error),
41
42    /// TOML deserialization failure.
43    #[error("TOML parse error: {0}")]
44    Toml(#[from] toml::de::Error),
45
46    /// A required file was not found.
47    #[error("file not found: {}", .0.display())]
48    FileNotFound(PathBuf),
49
50    /// Embedding API error.
51    #[error("embedding error: {0}")]
52    Embedding(String),
53
54    /// Database operation failure.
55    #[error("database error: {0}")]
56    Database(String),
57}
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn io_error_converts() {
65        let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "gone");
66        let err: ArgusError = io_err.into();
67        assert!(err.to_string().contains("gone"));
68    }
69
70    #[test]
71    fn config_error_displays_message() {
72        let err = ArgusError::Config("bad value".into());
73        assert_eq!(err.to_string(), "configuration error: bad value");
74    }
75
76    #[test]
77    fn file_not_found_shows_path() {
78        let err = ArgusError::FileNotFound(PathBuf::from("/tmp/missing.rs"));
79        assert!(err.to_string().contains("/tmp/missing.rs"));
80    }
81}