openapi_nexus_go/
errors.rs

1//! Error types for Go code generation
2
3use snafu::Snafu;
4
5/// Error type for Go code generation
6#[derive(Debug, Snafu)]
7#[snafu(visibility(pub))]
8pub enum GeneratorError {
9    /// Template rendering error
10    #[snafu(display("Failed to render template '{}': {}", template_path, source))]
11    TemplateRender {
12        template_path: String,
13        source: minijinja::Error,
14    },
15
16    /// Template not found error
17    #[snafu(display("Template '{}' not found: {}", template_path, source))]
18    TemplateNotFound {
19        template_path: String,
20        source: minijinja::Error,
21    },
22
23    /// API client generation error
24    #[snafu(display("Failed to generate API client '{}': {}", client_name, source))]
25    ApiClientGeneration {
26        client_name: String,
27        source: Box<dyn std::error::Error + Send + Sync>,
28    },
29
30    /// Model generation error
31    #[snafu(display("Failed to generate model '{}': {}", model_name, source))]
32    ModelGeneration {
33        model_name: String,
34        source: Box<dyn std::error::Error + Send + Sync>,
35    },
36
37    /// Type mapping error
38    #[snafu(display("Failed to map type: {}", source))]
39    TypeMapping {
40        source: Box<dyn std::error::Error + Send + Sync>,
41    },
42
43    /// File I/O error
44    #[snafu(display("File I/O error: {}", source))]
45    Io { source: std::io::Error },
46
47    /// Config parsing error
48    #[snafu(display("Failed to parse config: {}", source))]
49    ConfigParse { source: toml::de::Error },
50
51    /// Generic error for cases that don't fit other categories
52    #[snafu(display("Generator error: {}", message))]
53    Generic { message: String },
54}
55
56impl From<std::io::Error> for GeneratorError {
57    fn from(err: std::io::Error) -> Self {
58        GeneratorError::Io { source: err }
59    }
60}
61
62impl From<toml::de::Error> for GeneratorError {
63    fn from(err: toml::de::Error) -> Self {
64        GeneratorError::ConfigParse { source: err }
65    }
66}
67
68impl From<Box<dyn std::error::Error + Send + Sync>> for GeneratorError {
69    fn from(err: Box<dyn std::error::Error + Send + Sync>) -> Self {
70        GeneratorError::Generic {
71            message: err.to_string(),
72        }
73    }
74}