Skip to main content

barbacane_compiler/
error.rs

1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4/// A warning produced during compilation (non-blocking).
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct CompileWarning {
7    /// Warning code (e.g., "E1015").
8    pub code: String,
9    /// Warning message.
10    pub message: String,
11    /// Location in the spec (e.g., "GET /users in 'api.yaml'").
12    pub location: Option<String>,
13}
14
15/// Errors produced during compilation.
16#[derive(Debug, Error)]
17pub enum CompileError {
18    /// Spec parsing failed.
19    #[error(transparent)]
20    Parse(#[from] crate::spec_parser::ParseError),
21
22    /// E1010: Routing conflict.
23    #[error("E1010: routing conflict: {0}")]
24    RoutingConflict(String),
25
26    /// E1020: Operation has no dispatcher.
27    #[error("E1020: operation has no x-barbacane-dispatch: {0}")]
28    MissingDispatch(String),
29
30    /// E1031: Plaintext HTTP upstream URL in production mode.
31    #[error("E1031: plaintext HTTP upstream URL not allowed in production: {0}")]
32    PlaintextUpstream(String),
33
34    /// E1040: Plugin used in spec but not declared in manifest.
35    #[error("E1040: plugin '{0}' used in spec but not declared in barbacane.yaml")]
36    UndeclaredPlugin(String),
37
38    /// E1011: Middleware entry missing required 'name' field.
39    #[error("E1011: middleware missing 'name': {0}")]
40    MissingMiddlewareName(String),
41
42    /// E1050: Ambiguous route - paths are structurally equivalent but differ in parameter names.
43    #[error("E1050: ambiguous route: {0}")]
44    AmbiguousRoute(String),
45
46    /// E1051: Schema exceeds maximum nesting depth.
47    #[error("E1051: schema too deep: {0}")]
48    SchemaTooDeep(String),
49
50    /// E1052: Schema exceeds maximum property count.
51    #[error("E1052: schema too complex: {0}")]
52    SchemaTooComplex(String),
53
54    /// E1054: Invalid path template syntax.
55    #[error("E1054: invalid path template: {0}")]
56    InvalidPathTemplate(String),
57
58    /// E1055: Duplicate operationId across specs.
59    #[error("E1055: duplicate operationId '{0}': {1}")]
60    DuplicateOperationId(String, String),
61
62    /// Manifest parsing or loading error.
63    #[error("manifest error: {0}")]
64    ManifestError(String),
65
66    /// Plugin resolution error (loading WASM bytes).
67    #[error("plugin resolution error: {0}")]
68    PluginResolution(String),
69
70    /// I/O error.
71    #[error("I/O error: {0}")]
72    Io(#[from] std::io::Error),
73
74    /// JSON serialization error.
75    #[error("JSON error: {0}")]
76    Json(#[from] serde_json::Error),
77}