1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum GeneratorError {
5 #[error("Failed to parse OpenAPI spec: {0}")]
6 ParseError(#[from] serde_json::Error),
7
8 #[error("Unresolved schema reference: {0}")]
9 UnresolvedReference(String),
10
11 #[error("Circular dependency detected: {0}")]
12 CircularDependency(String),
13
14 #[error("Invalid discriminator pattern in schema: {0}")]
15 InvalidDiscriminator(String),
16
17 #[error("Code generation failed: {0}")]
18 CodeGenError(String),
19
20 #[error("IO error: {0}")]
21 IoError(#[from] std::io::Error),
22
23 #[error("Invalid schema: {0}")]
24 InvalidSchema(String),
25
26 #[error("Validation error: {0}")]
27 ValidationError(String),
28
29 #[error("File error: {message}")]
30 FileError { message: String },
31}
32
33impl GeneratorError {
34 pub fn with_context(self, schema_name: &str) -> Self {
35 match self {
36 Self::CodeGenError(msg) => {
37 Self::CodeGenError(format!("{msg} (in schema: {schema_name})"))
38 }
39 Self::InvalidSchema(msg) => {
40 Self::InvalidSchema(format!("{msg} (in schema: {schema_name})"))
41 }
42 other => other,
43 }
44 }
45}