1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, BevyAIError>;
7
8#[derive(Error, Debug)]
10pub enum BevyAIError {
11 #[error("Configuration error: {0}")]
13 Config(#[from] config::ConfigError),
14
15 #[error("HTTP request failed: {0}")]
17 Http(#[from] reqwest::Error),
18
19 #[error("JSON serialization/deserialization error: {0}")]
21 Json(#[from] serde_json::Error),
22
23 #[error("IO error: {0}")]
25 Io(#[from] std::io::Error),
26
27 #[error("File traversal error: {0}")]
29 WalkDir(#[from] walkdir::Error),
30
31 #[error("Template rendering error: {0}")]
33 Template(#[from] handlebars::RenderError),
34
35 #[error("Template creation error: {0}")]
37 TemplateCreation(#[from] handlebars::TemplateError),
38
39 #[error("Code parsing error: {0}")]
41 CodeParsing(String),
42
43 #[error("AI API error: {message}")]
45 AIApi {
46 message: String
48 },
49
50 #[error("API key not configured for {provider}")]
52 MissingApiKey {
53 provider: String
55 },
56
57 #[error("Unsupported AI model: {model}")]
59 UnsupportedModel {
60 model: String
62 },
63
64 #[error("Project not found at path: {path}")]
66 ProjectNotFound {
67 path: String
69 },
70
71 #[error("Invalid project structure: {reason}")]
73 InvalidProject {
74 reason: String
76 },
77
78 #[error("Feature generation failed: {reason}")]
80 FeatureGeneration {
81 reason: String
83 },
84
85 #[error("Code optimization failed: {reason}")]
87 CodeOptimization {
88 reason: String
90 },
91
92 #[error("File operation failed: {operation} on {path}")]
94 FileOperation {
95 operation: String,
97 path: String
99 },
100
101 #[error("Template not found: {name}")]
103 TemplateNotFound {
104 name: String
106 },
107
108 #[error("Dependency resolution failed: {dependency}")]
110 DependencyResolution {
111 dependency: String
113 },
114
115 #[error("Build system error: {message}")]
117 BuildSystem {
118 message: String
120 },
121
122 #[error("Validation error: {message}")]
124 Validation {
125 message: String
127 },
128}
129
130impl BevyAIError {
131 pub fn ai_api<S: Into<String>>(message: S) -> Self {
133 Self::AIApi {
134 message: message.into(),
135 }
136 }
137
138 pub fn missing_api_key<S: Into<String>>(provider: S) -> Self {
140 Self::MissingApiKey {
141 provider: provider.into(),
142 }
143 }
144
145 pub fn unsupported_model<S: Into<String>>(model: S) -> Self {
147 Self::UnsupportedModel {
148 model: model.into(),
149 }
150 }
151
152 pub fn project_not_found<S: Into<String>>(path: S) -> Self {
154 Self::ProjectNotFound {
155 path: path.into(),
156 }
157 }
158
159 pub fn invalid_project<S: Into<String>>(reason: S) -> Self {
161 Self::InvalidProject {
162 reason: reason.into(),
163 }
164 }
165
166 pub fn feature_generation<S: Into<String>>(reason: S) -> Self {
168 Self::FeatureGeneration {
169 reason: reason.into(),
170 }
171 }
172
173 pub fn code_optimization<S: Into<String>>(reason: S) -> Self {
175 Self::CodeOptimization {
176 reason: reason.into(),
177 }
178 }
179
180 pub fn file_operation<S: Into<String>>(operation: S, path: S) -> Self {
182 Self::FileOperation {
183 operation: operation.into(),
184 path: path.into(),
185 }
186 }
187
188 pub fn template_not_found<S: Into<String>>(name: S) -> Self {
190 Self::TemplateNotFound {
191 name: name.into(),
192 }
193 }
194
195 pub fn dependency_resolution<S: Into<String>>(dependency: S) -> Self {
197 Self::DependencyResolution {
198 dependency: dependency.into(),
199 }
200 }
201
202 pub fn build_system<S: Into<String>>(message: S) -> Self {
204 Self::BuildSystem {
205 message: message.into(),
206 }
207 }
208
209 pub fn validation<S: Into<String>>(message: S) -> Self {
211 Self::Validation {
212 message: message.into(),
213 }
214 }
215}