1use std::path::PathBuf;
2
3use miette::Diagnostic;
4
5#[derive(Debug, thiserror::Error, Diagnostic)]
19pub enum ArgusError {
20 #[error("IO error: {0}")]
22 #[diagnostic(code(argus::io), help("Check file permissions and paths"))]
23 Io(#[from] std::io::Error),
24
25 #[error("Configuration error: {0}")]
27 #[diagnostic(
28 code(argus::config),
29 help("Run `argus init` to create a default config, or check .argus.toml syntax")
30 )]
31 Config(String),
32
33 #[error("Git error: {0}")]
35 #[diagnostic(code(argus::git), help("Make sure you're inside a git repository"))]
36 Git(String),
37
38 #[error("Parse error: {0}")]
40 #[diagnostic(
41 code(argus::parse),
42 help("Check that the file is valid source code in a supported language")
43 )]
44 Parse(String),
45
46 #[error("LLM error: {0}")]
48 #[diagnostic(code(argus::llm), help("Check your API key and provider config in .argus.toml. Run `argus doctor` to diagnose."))]
49 Llm(String),
50
51 #[error("Serialization error: {0}")]
53 #[diagnostic(code(argus::serde))]
54 Serialization(#[from] serde_json::Error),
55
56 #[error("TOML parse error: {0}")]
58 #[diagnostic(
59 code(argus::toml),
60 help("Check .argus.toml syntax — run `argus init` to generate a fresh one")
61 )]
62 Toml(#[from] toml::de::Error),
63
64 #[error("File not found: {}", .0.display())]
66 #[diagnostic(
67 code(argus::file_not_found),
68 help("Check the path exists and is readable")
69 )]
70 FileNotFound(PathBuf),
71
72 #[error("Embedding error: {0}")]
74 #[diagnostic(
75 code(argus::embedding),
76 help("Check your embedding provider API key. Run `argus doctor` to diagnose.")
77 )]
78 Embedding(String),
79
80 #[error("Database error: {0}")]
82 #[diagnostic(
83 code(argus::database),
84 help("Try deleting .argus/index.db and re-indexing")
85 )]
86 Database(String),
87}
88
89#[cfg(test)]
90mod tests {
91 use super::*;
92
93 #[test]
94 fn io_error_converts() {
95 let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "gone");
96 let err: ArgusError = io_err.into();
97 assert!(err.to_string().contains("gone"));
98 }
99
100 #[test]
101 fn config_error_displays_message() {
102 let err = ArgusError::Config("bad value".into());
103 assert_eq!(err.to_string(), "Configuration error: bad value");
104 }
105
106 #[test]
107 fn file_not_found_shows_path() {
108 let err = ArgusError::FileNotFound(PathBuf::from("/tmp/missing.rs"));
109 assert!(err.to_string().contains("/tmp/missing.rs"));
110 }
111}