elif_openapi/
error.rs

1use thiserror::Error;
2
3/// Result type for OpenAPI operations
4pub type OpenApiResult<T> = Result<T, OpenApiError>;
5
6/// Errors that can occur during OpenAPI generation
7#[derive(Debug, Error)]
8pub enum OpenApiError {
9    /// JSON serialization/deserialization error
10    #[error("JSON error: {0}")]
11    Json(#[from] serde_json::Error),
12
13    /// YAML serialization/deserialization error
14    #[error("YAML error: {0}")]
15    Yaml(#[from] serde_yaml::Error),
16
17    /// I/O error (file operations, etc.)
18    #[error("I/O error: {0}")]
19    Io(#[from] std::io::Error),
20
21    /// HTTP request error
22    #[error("HTTP error: {0}")]
23    Http(#[from] reqwest::Error),
24
25    /// Schema generation error
26    #[error("Schema generation error: {0}")]
27    Schema(String),
28
29    /// Route discovery error
30    #[error("Route discovery error: {0}")]
31    RouteDiscovery(String),
32
33    /// Configuration error
34    #[error("Configuration error: {0}")]
35    Config(String),
36
37    /// Export format error
38    #[error("Export format error: {0}")]
39    Export(String),
40
41    /// Validation error
42    #[error("Validation error: {0}")]
43    Validation(String),
44
45    /// Generic error with context
46    #[error("OpenAPI error: {0}")]
47    Generic(String),
48}
49
50impl OpenApiError {
51    /// Create a new schema generation error
52    pub fn schema_error<T: ToString>(msg: T) -> Self {
53        Self::Schema(msg.to_string())
54    }
55
56    /// Create a new route discovery error
57    pub fn route_discovery_error<T: ToString>(msg: T) -> Self {
58        Self::RouteDiscovery(msg.to_string())
59    }
60
61    /// Create a new configuration error
62    pub fn config_error<T: ToString>(msg: T) -> Self {
63        Self::Config(msg.to_string())
64    }
65
66    /// Create a new export format error
67    pub fn export_error<T: ToString>(msg: T) -> Self {
68        Self::Export(msg.to_string())
69    }
70
71    /// Create a new validation error
72    pub fn validation_error<T: ToString>(msg: T) -> Self {
73        Self::Validation(msg.to_string())
74    }
75
76    /// Create a generic error
77    pub fn generic<T: ToString>(msg: T) -> Self {
78        Self::Generic(msg.to_string())
79    }
80}