Skip to main content

wesley_core/domain/
error.rs

1//! Domain error types.
2
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6/// Core error types for Wesley.
7#[derive(Error, Debug, Serialize, Deserialize, Clone, PartialEq)]
8pub enum WesleyError {
9    /// Error during parsing of GraphQL SDL.
10    #[error("Parse error: {message}")]
11    ParseError {
12        /// Human-readable error message.
13        message: String,
14        /// Line number (if available).
15        line: Option<u32>,
16        /// Column number (if available).
17        column: Option<u32>,
18    },
19    /// Error during lowering from AST to IR.
20    #[error("Lowering error: {message} in {area}")]
21    LoweringError {
22        /// Human-readable error message.
23        message: String,
24        /// The area of the compiler where the error occurred (e.g. "table", "field").
25        area: String,
26    },
27    /// Error from a resilience policy (e.g. timeout, max retries).
28    #[error("Resilience error: {0}")]
29    ResilienceError(String),
30}
31
32impl WesleyError {
33    /// Returns the stable diagnostic contract for this error.
34    pub fn diagnostic(&self) -> WesleyDiagnostic {
35        match self {
36            Self::ParseError {
37                message,
38                line,
39                column,
40            } => WesleyDiagnostic {
41                code: "WESLEY_PARSE_ERROR".to_string(),
42                message: message.clone(),
43                severity: "ERROR".to_string(),
44                line: *line,
45                column: *column,
46            },
47            Self::LoweringError { message, .. } => WesleyDiagnostic {
48                code: "WESLEY_LOWERING_ERROR".to_string(),
49                message: message.clone(),
50                severity: "ERROR".to_string(),
51                line: None,
52                column: None,
53            },
54            Self::ResilienceError(message) => WesleyDiagnostic {
55                code: "WESLEY_RESILIENCE_ERROR".to_string(),
56                message: message.clone(),
57                severity: "ERROR".to_string(),
58                line: None,
59                column: None,
60            },
61        }
62    }
63}
64
65/// A diagnostic message emitted by the compiler.
66#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
67pub struct WesleyDiagnostic {
68    /// Machine-readable error code.
69    pub code: String,
70    /// Human-readable error message.
71    pub message: String,
72    /// Severity level (e.g. "ERROR", "WARNING").
73    pub severity: String,
74    /// Line number (if available).
75    pub line: Option<u32>,
76    /// Column number (if available).
77    pub column: Option<u32>,
78}