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
28#[derive(Error, Debug)]
29pub enum AnalysisError {
30    #[error("Unsupported project type: {0}")]
31    UnsupportedProject(String),
32
33    #[error("Failed to detect language in {path}")]
34    LanguageDetection { path: PathBuf },
35
36    #[error("Dependency parsing failed for {file}: {reason}")]
37    DependencyParsing { file: String, reason: String },
38
39    #[error("Framework detection failed: {0}")]
40    FrameworkDetection(String),
41
42    #[error("Invalid project structure: {0}")]
43    InvalidStructure(String),
44}
45
46#[derive(Error, Debug)]
47pub enum GeneratorError {
48    #[error("Template rendering failed: {0}")]
49    TemplateRendering(String),
50
51    #[error("Unsupported generator type: {0}")]
52    UnsupportedGenerator(String),
53
54    #[error("Output file creation failed: {path}")]
55    OutputCreation { path: PathBuf },
56
57    #[error("Invalid generation context: {0}")]
58    InvalidContext(String),
59}
60
61#[derive(Error, Debug)]
62pub enum ConfigError {
63    #[error("Invalid configuration file: {0}")]
64    InvalidFile(String),
65
66    #[error("Missing required configuration: {0}")]
67    MissingConfig(String),
68
69    #[error("Configuration parsing failed: {0}")]
70    ParsingFailed(String),
71}
72
73#[derive(Error, Debug)]
74pub enum SecurityError {
75    #[error("Invalid path: path traversal detected")]
76    PathTraversal,
77
78    #[error("Invalid path: {0}")]
79    InvalidPath(String),
80
81    #[error("Insufficient permissions: {0}")]
82    InsufficientPermissions(String),
83}
84
85pub type Result<T> = std::result::Result<T, IaCGeneratorError>;