openapi_nexus_typescript/
errors.rs1use snafu::Snafu;
4
5#[derive(Debug, Snafu)]
7#[snafu(visibility(pub))]
8pub enum GeneratorError {
9 #[snafu(display("Failed to render template '{}': {}", template_path, source))]
11 TemplateRender {
12 template_path: String,
13 source: minijinja::Error,
14 },
15
16 #[snafu(display("Template '{}' not found: {}", template_path, source))]
18 TemplateNotFound {
19 template_path: String,
20 source: minijinja::Error,
21 },
22
23 #[snafu(display("Failed to generate API class '{}': {}", class_name, source))]
25 ApiClassGeneration {
26 class_name: String,
27 source: Box<dyn std::error::Error + Send + Sync>,
28 },
29
30 #[snafu(display("Failed to generate API class for tag '{}': {}", tag, source))]
32 ApiClassGenerationForTag {
33 tag: String,
34 source: Box<dyn std::error::Error + Send + Sync>,
35 },
36
37 #[snafu(display("Failed to generate interface model '{}': {}", model_name, source))]
39 ModelInterfaceGeneration {
40 model_name: String,
41 source: Box<dyn std::error::Error + Send + Sync>,
42 },
43
44 #[snafu(display("Failed to generate type alias model '{}': {}", model_name, source))]
46 ModelTypeAliasGeneration {
47 model_name: String,
48 source: Box<dyn std::error::Error + Send + Sync>,
49 },
50
51 #[snafu(display("Failed to generate enum model '{}': {}", model_name, source))]
53 ModelEnumGeneration {
54 model_name: String,
55 source: Box<dyn std::error::Error + Send + Sync>,
56 },
57
58 #[snafu(display("Failed to render runtime template: {}", source))]
60 RuntimeTemplate {
61 source: Box<dyn std::error::Error + Send + Sync>,
62 },
63
64 #[snafu(display("Failed to render index file '{}': {}", file_path, source))]
66 IndexFileGeneration {
67 file_path: String,
68 source: Box<dyn std::error::Error + Send + Sync>,
69 },
70
71 #[snafu(display(
73 "Unsupported HTTP method: {:?}. Only GET, POST, PUT, PATCH, and DELETE are supported.",
74 method
75 ))]
76 UnsupportedHttpMethod { method: http::Method },
77
78 #[snafu(display("Failed to extract parameters: {}", source))]
80 ParameterExtraction {
81 source: Box<dyn std::error::Error + Send + Sync>,
82 },
83
84 #[snafu(display("Failed to generate return type: {}", source))]
86 ReturnTypeGeneration {
87 source: Box<dyn std::error::Error + Send + Sync>,
88 },
89
90 #[snafu(display("File I/O error: {}", source))]
92 Io { source: std::io::Error },
93
94 #[snafu(display("Failed to parse config: {}", source))]
96 ConfigParse { source: toml::de::Error },
97
98 #[snafu(display("Generator error: {}", message))]
100 Generic { message: String },
101}
102
103impl From<minijinja::Error> for GeneratorError {
104 fn from(err: minijinja::Error) -> Self {
105 GeneratorError::Generic {
106 message: err.to_string(),
107 }
108 }
109}
110
111impl From<std::io::Error> for GeneratorError {
112 fn from(err: std::io::Error) -> Self {
113 GeneratorError::Io { source: err }
114 }
115}
116
117impl From<toml::de::Error> for GeneratorError {
118 fn from(err: toml::de::Error) -> Self {
119 GeneratorError::ConfigParse { source: err }
120 }
121}
122
123impl From<Box<dyn std::error::Error + Send + Sync>> for GeneratorError {
124 fn from(err: Box<dyn std::error::Error + Send + Sync>) -> Self {
125 GeneratorError::Generic {
126 message: err.to_string(),
127 }
128 }
129}