1use std::path::PathBuf;
2use thiserror::Error;
3
4pub type Result<T> = std::result::Result<T, AuditError>;
6
7#[derive(Debug, Error)]
9pub enum AuditError {
10 #[error("Failed to parse documentation file: {path}")]
11 DocumentationParseError { path: PathBuf },
12
13 #[error("Failed to analyze crate: {crate_name} - {details}")]
14 CrateAnalysisError { crate_name: String, details: String },
15
16 #[error("Code example compilation failed: {details}")]
17 CompilationError { details: String },
18
19 #[error("Workspace not found at path: {path}")]
20 WorkspaceNotFound { path: PathBuf },
21
22 #[error("Invalid configuration: {message}")]
23 ConfigurationError { message: String },
24
25 #[error("Database error: {details}")]
26 DatabaseError { details: String },
27
28 #[error("IO error accessing {path}: {details}")]
29 IoError { path: PathBuf, details: String },
30
31 #[error("API reference validation failed: {api_path} in {crate_name}")]
32 ApiValidationError { api_path: String, crate_name: String },
33
34 #[error("Version inconsistency: expected {expected}, found {found} in {file_path}")]
35 VersionInconsistency { expected: String, found: String, file_path: PathBuf },
36
37 #[error("Internal link broken: {link} in {file_path}")]
38 BrokenLinkError { link: String, file_path: PathBuf },
39
40 #[error("Feature flag '{flag}' not found in crate '{crate_name}'")]
41 FeatureFlagNotFound { flag: String, crate_name: String },
42
43 #[error("Temporary directory creation failed: {details}")]
44 TempDirError { details: String },
45
46 #[error("Cargo command failed: {command} - {output}")]
47 CargoError { command: String, output: String },
48
49 #[error("Regex compilation failed: {pattern} - {details}")]
50 RegexError { pattern: String, details: String },
51
52 #[error("JSON serialization/deserialization error: {details}")]
53 JsonError { details: String },
54
55 #[error("TOML parsing error in {file_path}: {details}")]
56 TomlError { file_path: PathBuf, details: String },
57
58 #[error("Markdown parsing error in {file_path}: {details}")]
59 MarkdownError { file_path: PathBuf, details: String },
60
61 #[error("Rust syntax parsing error: {details}")]
62 SyntaxError { details: String },
63
64 #[error("Report generation failed: {details}")]
65 ReportGeneration { details: String },
66
67 #[error("File not found: {path}")]
68 FileNotFound { path: PathBuf },
69
70 #[error("Invalid file type: {path}, expected {expected}")]
71 InvalidFileType { path: PathBuf, expected: String },
72
73 #[error("Processing error: {details}")]
74 ProcessingError { details: String },
75}
76
77impl From<std::io::Error> for AuditError {
78 fn from(err: std::io::Error) -> Self {
79 AuditError::IoError { path: PathBuf::from("<unknown>"), details: err.to_string() }
80 }
81}
82
83impl From<serde_json::Error> for AuditError {
84 fn from(err: serde_json::Error) -> Self {
85 AuditError::JsonError { details: err.to_string() }
86 }
87}
88
89impl From<regex::Error> for AuditError {
90 fn from(err: regex::Error) -> Self {
91 AuditError::RegexError { pattern: "<unknown>".to_string(), details: err.to_string() }
92 }
93}
94
95impl From<rusqlite::Error> for AuditError {
96 fn from(err: rusqlite::Error) -> Self {
97 AuditError::DatabaseError { details: err.to_string() }
98 }
99}
100
101impl From<syn::Error> for AuditError {
102 fn from(err: syn::Error) -> Self {
103 AuditError::SyntaxError { details: err.to_string() }
104 }
105}
106
107impl From<toml::de::Error> for AuditError {
108 fn from(err: toml::de::Error) -> Self {
109 AuditError::TomlError { file_path: PathBuf::from("<unknown>"), details: err.to_string() }
110 }
111}