1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//! Error types and utilities for Bevy AI
use thiserror::Error;
/// Result type alias for Bevy AI operations
pub type Result<T> = std::result::Result<T, BevyAIError>;
/// Main error type for Bevy AI operations
#[derive(Error, Debug)]
pub enum BevyAIError {
/// Configuration-related errors
#[error("Configuration error: {0}")]
Config(#[from] config::ConfigError),
/// HTTP request errors
#[error("HTTP request failed: {0}")]
Http(#[from] reqwest::Error),
/// JSON serialization/deserialization errors
#[error("JSON serialization/deserialization error: {0}")]
Json(#[from] serde_json::Error),
/// Input/output errors
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
/// File system traversal errors
#[error("File traversal error: {0}")]
WalkDir(#[from] walkdir::Error),
/// Template rendering errors
#[error("Template rendering error: {0}")]
Template(#[from] handlebars::RenderError),
/// Template creation errors
#[error("Template creation error: {0}")]
TemplateCreation(#[from] handlebars::TemplateError),
/// Code parsing errors
#[error("Code parsing error: {0}")]
CodeParsing(String),
/// AI API communication errors
#[error("AI API error: {message}")]
AIApi {
/// The error message from the AI API
message: String
},
/// Missing API key errors
#[error("API key not configured for {provider}")]
MissingApiKey {
/// The AI provider that requires an API key
provider: String
},
/// Unsupported model errors
#[error("Unsupported AI model: {model}")]
UnsupportedModel {
/// The unsupported model name
model: String
},
/// Project not found errors
#[error("Project not found at path: {path}")]
ProjectNotFound {
/// The path where the project was expected
path: String
},
/// Invalid project structure errors
#[error("Invalid project structure: {reason}")]
InvalidProject {
/// The reason why the project is invalid
reason: String
},
/// Feature generation errors
#[error("Feature generation failed: {reason}")]
FeatureGeneration {
/// The reason why feature generation failed
reason: String
},
/// Code optimization errors
#[error("Code optimization failed: {reason}")]
CodeOptimization {
/// The reason why code optimization failed
reason: String
},
/// File operation errors
#[error("File operation failed: {operation} on {path}")]
FileOperation {
/// The operation that failed
operation: String,
/// The path where the operation failed
path: String
},
/// Template not found errors
#[error("Template not found: {name}")]
TemplateNotFound {
/// The name of the template that wasn't found
name: String
},
/// Dependency resolution errors
#[error("Dependency resolution failed: {dependency}")]
DependencyResolution {
/// The dependency that couldn't be resolved
dependency: String
},
/// Build system errors
#[error("Build system error: {message}")]
BuildSystem {
/// The build system error message
message: String
},
/// Validation errors
#[error("Validation error: {message}")]
Validation {
/// The validation error message
message: String
},
}
impl BevyAIError {
/// Create a new AI API error
pub fn ai_api<S: Into<String>>(message: S) -> Self {
Self::AIApi {
message: message.into(),
}
}
/// Create a new missing API key error
pub fn missing_api_key<S: Into<String>>(provider: S) -> Self {
Self::MissingApiKey {
provider: provider.into(),
}
}
/// Create a new unsupported model error
pub fn unsupported_model<S: Into<String>>(model: S) -> Self {
Self::UnsupportedModel {
model: model.into(),
}
}
/// Create a new project not found error
pub fn project_not_found<S: Into<String>>(path: S) -> Self {
Self::ProjectNotFound {
path: path.into(),
}
}
/// Create a new invalid project error
pub fn invalid_project<S: Into<String>>(reason: S) -> Self {
Self::InvalidProject {
reason: reason.into(),
}
}
/// Create a new feature generation error
pub fn feature_generation<S: Into<String>>(reason: S) -> Self {
Self::FeatureGeneration {
reason: reason.into(),
}
}
/// Create a new code optimization error
pub fn code_optimization<S: Into<String>>(reason: S) -> Self {
Self::CodeOptimization {
reason: reason.into(),
}
}
/// Create a new file operation error
pub fn file_operation<S: Into<String>>(operation: S, path: S) -> Self {
Self::FileOperation {
operation: operation.into(),
path: path.into(),
}
}
/// Create a new template not found error
pub fn template_not_found<S: Into<String>>(name: S) -> Self {
Self::TemplateNotFound {
name: name.into(),
}
}
/// Create a new dependency resolution error
pub fn dependency_resolution<S: Into<String>>(dependency: S) -> Self {
Self::DependencyResolution {
dependency: dependency.into(),
}
}
/// Create a new build system error
pub fn build_system<S: Into<String>>(message: S) -> Self {
Self::BuildSystem {
message: message.into(),
}
}
/// Create a new validation error
pub fn validation<S: Into<String>>(message: S) -> Self {
Self::Validation {
message: message.into(),
}
}
}