dampen_cli/commands/check/
errors.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4/// Enhanced error types for the `dampen check` command.
5#[derive(Error, Debug)]
6pub enum CheckError {
7    // Phase 1: Unknown Attribute Detection
8    #[error("Unknown attribute '{attr}' for widget '{widget}' in {file}:{line}:{col}{suggestion}")]
9    UnknownAttribute {
10        attr: String,
11        widget: String,
12        file: PathBuf,
13        line: u32,
14        col: u32,
15        suggestion: String,
16    },
17
18    // Phase 7: Required Attribute Validation
19    #[error("Missing required attribute '{attr}' for widget '{widget}' in {file}:{line}:{col}")]
20    MissingRequiredAttribute {
21        attr: String,
22        widget: String,
23        file: PathBuf,
24        line: u32,
25        col: u32,
26    },
27
28    // Phase 2: Handler Registry Validation
29    #[error("Unknown handler '{handler}' in {file}:{line}:{col}{suggestion}")]
30    UnknownHandler {
31        handler: String,
32        file: PathBuf,
33        line: u32,
34        col: u32,
35        suggestion: String,
36    },
37
38    // Phase 3: Binding Validation Against Model
39    #[error(
40        "Invalid binding field '{field}' in {file}:{line}:{col}. Available fields: {available}"
41    )]
42    InvalidBindingField {
43        field: String,
44        file: PathBuf,
45        line: u32,
46        col: u32,
47        available: String,
48    },
49
50    // Phase 4: Radio Group Validation
51    #[error("Duplicate radio value '{value}' in group '{group}' at {file}:{line}:{col}. First occurrence: {first_file}:{first_line}:{first_col}")]
52    DuplicateRadioValue {
53        value: String,
54        group: String,
55        file: PathBuf,
56        line: u32,
57        col: u32,
58        first_file: PathBuf,
59        first_line: u32,
60        first_col: u32,
61    },
62
63    #[error("Radio group '{group}' has inconsistent on_select handlers in {file}:{line}:{col}. Found handlers: {handlers}")]
64    InconsistentRadioHandlers {
65        group: String,
66        file: PathBuf,
67        line: u32,
68        col: u32,
69        handlers: String,
70    },
71
72    // Phase 5: Theme Property Validation
73    #[error("Invalid theme property '{property}' in theme '{theme}' at {file}:{line}:{col}: {message}. Valid properties: {valid_properties}")]
74    InvalidThemeProperty {
75        property: String,
76        theme: String,
77        file: PathBuf,
78        line: u32,
79        col: u32,
80        message: String,
81        valid_properties: String,
82    },
83
84    #[error("Theme '{theme}' has circular dependency: {cycle}")]
85    ThemeCircularDependency { theme: String, cycle: String },
86
87    // JSON loading errors
88    #[error("Failed to load handler registry from {path}: {source}")]
89    HandlerRegistryLoadError {
90        path: PathBuf,
91        source: serde_json::Error,
92    },
93
94    #[error("Failed to load model info from {path}: {source}")]
95    ModelInfoLoadError {
96        path: PathBuf,
97        source: serde_json::Error,
98    },
99
100    #[error("Failed to load custom widget config from {path}: {source}")]
101    CustomWidgetConfigLoadError {
102        path: PathBuf,
103        source: serde_json::Error,
104    },
105
106    // Generic errors
107    #[error("IO error: {0}")]
108    Io(#[from] std::io::Error),
109}