llm_config_devtools/
error.rs1use std::path::PathBuf;
6use thiserror::Error;
7
8pub type Result<T> = std::result::Result<T, DevtoolsError>;
10
11#[derive(Error, Debug)]
13pub enum DevtoolsError {
14 #[error("IO error: {0}")]
16 Io(#[from] std::io::Error),
17
18 #[error("Cargo command failed: {0}")]
20 CargoExecution(String),
21
22 #[error("Failed to parse cargo metadata: {0}")]
24 CargoMetadata(#[from] cargo_metadata::Error),
25
26 #[error("Clippy execution failed: {0}")]
28 ClippyFailed(String),
29
30 #[error("Pattern compilation failed: {0}")]
32 PatternError(#[from] regex::Error),
33
34 #[error("Invalid project root: {path}")]
36 InvalidProjectRoot {
37 path: PathBuf
39 },
40
41 #[error("No Cargo.toml found at: {path}")]
43 NoCargoToml {
44 path: PathBuf
46 },
47
48 #[error("Serialization error: {0}")]
50 Serialization(String),
51
52 #[error("Deserialization error: {0}")]
54 Deserialization(String),
55
56 #[error("Report generation failed: {0}")]
58 ReportGeneration(String),
59
60 #[error("Git error: {0}")]
62 Git(#[from] git2::Error),
63
64 #[error("No security findings to report")]
66 NoFindings,
67
68 #[error("Configuration error: {0}")]
70 Config(String),
71
72 #[error("File walking error: {0}")]
74 Ignore(String),
75
76 #[error("{0}")]
78 Other(String),
79}
80
81impl From<ignore::Error> for DevtoolsError {
82 fn from(err: ignore::Error) -> Self {
83 DevtoolsError::Ignore(err.to_string())
84 }
85}
86
87impl From<serde_json::Error> for DevtoolsError {
88 fn from(err: serde_json::Error) -> Self {
89 DevtoolsError::Serialization(err.to_string())
90 }
91}
92
93impl From<serde_yaml::Error> for DevtoolsError {
94 fn from(err: serde_yaml::Error) -> Self {
95 DevtoolsError::Serialization(err.to_string())
96 }
97}
98
99#[cfg(test)]
100mod tests {
101 use super::*;
102
103 #[test]
104 fn test_error_display() {
105 let err = DevtoolsError::CargoExecution("test error".to_string());
106 assert_eq!(err.to_string(), "Cargo command failed: test error");
107 }
108
109 #[test]
110 fn test_invalid_project_root() {
111 let err = DevtoolsError::InvalidProjectRoot {
112 path: PathBuf::from("/invalid/path"),
113 };
114 assert!(err.to_string().contains("/invalid/path"));
115 }
116}