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 index is malformed: {reason}")]
73    MalformedRegistry { reason: String },
74
75    #[error("🔸 Registry component missing required fields")]
76    RegistryComponentMissing,
77
78    #[error("🔸 Registry has invalid format")]
79    RegistryInvalidFormat,
80
81    #[error("🔸 Project not initialized. Run 'ui init' to initialize the project first.")]
82    ProjectNotInitialized,
83}
84
85impl CliError {
86    pub fn file_operation(message: &str) -> Self {
87        Self::FileOperation { message: message.to_string() }
88    }
89
90    pub fn config(message: &str) -> Self {
91        Self::Config { message: message.to_string() }
92    }
93
94    pub fn cargo_operation(message: &str) -> Self {
95        Self::CargoOperation { message: message.to_string() }
96    }
97
98    pub fn invalid_path(path: &str, reason: &str) -> Self {
99        Self::InvalidPath { path: path.to_string(), reason: reason.to_string() }
100    }
101
102    pub fn validation(message: &str) -> Self {
103        Self::Validation { message: message.to_string() }
104    }
105
106    pub fn malformed_registry(reason: &str) -> Self {
107        Self::MalformedRegistry { reason: reason.to_string() }
108    }
109
110    pub fn registry_request_failed() -> Self {
111        Self::RegistryRequestFailed
112    }
113
114    pub fn directory_create_failed() -> Self {
115        Self::DirectoryCreateFailed
116    }
117
118    pub fn file_write_failed() -> Self {
119        Self::FileWriteFailed
120    }
121
122    pub fn file_read_failed() -> Self {
123        Self::FileReadFailed
124    }
125
126    pub fn npm_install_failed() -> Self {
127        Self::NpmInstallFailed
128    }
129
130    pub fn git_clone_failed() -> Self {
131        Self::GitCloneFailed
132    }
133
134    pub fn registry_component_missing() -> Self {
135        Self::RegistryComponentMissing
136    }
137
138    pub fn registry_invalid_format() -> Self {
139        Self::RegistryInvalidFormat
140    }
141
142    pub fn project_not_initialized() -> Self {
143        Self::ProjectNotInitialized
144    }
145}
146
147pub type CliResult<T> = std::result::Result<T, CliError>;