Skip to main content

ui_cli/shared/
cli_error.rs

1#[derive(Debug, thiserror::Error)]
2pub enum CliError {
3    #[error("🔸 Registry request failed")]
4    RegistryRequestFailed,
5
6    #[error("🔸 Network request failed: {source}")]
7    Network {
8        #[from]
9        source: reqwest::Error,
10    },
11
12    #[error("🔸 File operation failed: {message}")]
13    FileOperation { message: String },
14
15    #[error("🔸 Failed to create directory")]
16    DirectoryCreateFailed,
17
18    #[error("🔸 Failed to write file")]
19    FileWriteFailed,
20
21    #[error("🔸 Failed to read file")]
22    FileReadFailed,
23
24    #[error("🔸 IO error: {source}")]
25    Io {
26        #[from]
27        source: std::io::Error,
28    },
29
30    #[error("🔸 Configuration error: {message}")]
31    Config { message: String },
32
33    #[error("🔸 Failed to parse TOML configuration: {source}")]
34    TomlParse {
35        #[from]
36        source: toml::de::Error,
37    },
38
39    #[error("🔸 Failed to serialize TOML configuration: {source}")]
40    TomlSerialize {
41        #[from]
42        source: toml::ser::Error,
43    },
44
45    #[error("🔸 Failed to parse Cargo.toml: {source}")]
46    CargoTomlParse {
47        #[from]
48        source: cargo_toml::Error,
49    },
50
51    #[error("🔸 JSON parsing error: {source}")]
52    JsonParse {
53        #[from]
54        source: serde_json::Error,
55    },
56
57    #[error("🔸 npm install failed")]
58    NpmInstallFailed,
59
60    #[error("🔸 Git clone failed")]
61    GitCloneFailed,
62
63    #[error("🔸 Cargo operation failed: {message}")]
64    CargoOperation { message: String },
65
66    #[error("🔸 Path validation error: {path} - {reason}")]
67    InvalidPath { path: String, reason: String },
68
69    #[error("🔸 Validation error: {message}")]
70    Validation { message: String },
71
72    #[error("🔸 Registry component missing required fields")]
73    RegistryComponentMissing,
74
75    #[error("🔸 Project not initialized. Run 'ui init' to initialize the project first.")]
76    ProjectNotInitialized,
77}
78
79impl CliError {
80    pub fn file_operation(message: &str) -> Self {
81        Self::FileOperation { message: message.to_string() }
82    }
83
84    pub fn config(message: &str) -> Self {
85        Self::Config { message: message.to_string() }
86    }
87
88    pub fn cargo_operation(message: &str) -> Self {
89        Self::CargoOperation { message: message.to_string() }
90    }
91
92    pub fn invalid_path(path: &str, reason: &str) -> Self {
93        Self::InvalidPath { path: path.to_string(), reason: reason.to_string() }
94    }
95
96    pub fn validation(message: &str) -> Self {
97        Self::Validation { message: message.to_string() }
98    }
99
100    pub fn registry_request_failed() -> Self {
101        Self::RegistryRequestFailed
102    }
103
104    pub fn directory_create_failed() -> Self {
105        Self::DirectoryCreateFailed
106    }
107
108    pub fn file_write_failed() -> Self {
109        Self::FileWriteFailed
110    }
111
112    pub fn file_read_failed() -> Self {
113        Self::FileReadFailed
114    }
115
116    pub fn npm_install_failed() -> Self {
117        Self::NpmInstallFailed
118    }
119
120    pub fn git_clone_failed() -> Self {
121        Self::GitCloneFailed
122    }
123
124    pub fn registry_component_missing() -> Self {
125        Self::RegistryComponentMissing
126    }
127
128    pub fn project_not_initialized() -> Self {
129        Self::ProjectNotInitialized
130    }
131}
132
133pub type CliResult<T> = std::result::Result<T, CliError>;