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