syncable_cli/
error.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum IaCGeneratorError {
6    #[error("Project analysis failed: {0}")]
7    Analysis(#[from] AnalysisError),
8
9    #[error("IaC generation failed: {0}")]
10    Generation(#[from] GeneratorError),
11
12    #[error("Configuration error: {0}")]
13    Config(#[from] ConfigError),
14
15    #[error("IO error: {0}")]
16    Io(#[from] std::io::Error),
17
18    #[error("Walk directory error: {0}")]
19    WalkDir(#[from] walkdir::Error),
20
21    #[error("JSON serialization error: {0}")]
22    Json(#[from] serde_json::Error),
23
24    #[error("Security error: {0}")]
25    Security(#[from] SecurityError),
26
27    #[error("Agent error: {0}")]
28    Agent(#[from] crate::agent::AgentError),
29}
30
31#[derive(Error, Debug)]
32pub enum AnalysisError {
33    #[error("Unsupported project type: {0}")]
34    UnsupportedProject(String),
35
36    #[error("Failed to detect language in {path}")]
37    LanguageDetection { path: PathBuf },
38
39    #[error("Dependency parsing failed for {file}: {reason}")]
40    DependencyParsing { file: String, reason: String },
41
42    #[error("Framework detection failed: {0}")]
43    FrameworkDetection(String),
44
45    #[error("Invalid project structure: {0}")]
46    InvalidStructure(String),
47}
48
49#[derive(Error, Debug)]
50pub enum GeneratorError {
51    #[error("Template rendering failed: {0}")]
52    TemplateRendering(String),
53
54    #[error("Unsupported generator type: {0}")]
55    UnsupportedGenerator(String),
56
57    #[error("Output file creation failed: {path}")]
58    OutputCreation { path: PathBuf },
59
60    #[error("Invalid generation context: {0}")]
61    InvalidContext(String),
62}
63
64#[derive(Error, Debug)]
65pub enum ConfigError {
66    #[error("Invalid configuration file: {0}")]
67    InvalidFile(String),
68
69    #[error("Missing required configuration: {0}")]
70    MissingConfig(String),
71
72    #[error("Configuration parsing failed: {0}")]
73    ParsingFailed(String),
74}
75
76#[derive(Error, Debug)]
77pub enum SecurityError {
78    #[error("Invalid path: path traversal detected")]
79    PathTraversal,
80
81    #[error("Invalid path: {0}")]
82    InvalidPath(String),
83
84    #[error("Insufficient permissions: {0}")]
85    InsufficientPermissions(String),
86}
87
88pub type Result<T> = std::result::Result<T, IaCGeneratorError>;