wesley_core/domain/
error.rs1use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6#[derive(Error, Debug, Serialize, Deserialize, Clone, PartialEq)]
8pub enum WesleyError {
9 #[error("Parse error: {message}")]
11 ParseError {
12 message: String,
14 line: Option<u32>,
16 column: Option<u32>,
18 },
19 #[error("Lowering error: {message} in {area}")]
21 LoweringError {
22 message: String,
24 area: String,
26 },
27 #[error("Resilience error: {0}")]
29 ResilienceError(String),
30}
31
32impl WesleyError {
33 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#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
67pub struct WesleyDiagnostic {
68 pub code: String,
70 pub message: String,
72 pub severity: String,
74 pub line: Option<u32>,
76 pub column: Option<u32>,
78}