1use thiserror::Error;
21
22#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
23pub struct Position {
24 pub line: u32,
25 pub col: u32,
26}
27
28#[derive(Debug, Error)]
31pub enum PyQLError {
32 #[error(transparent)]
33 Syntax(#[from] PyQLSyntaxError),
34 #[error(transparent)]
35 Type(#[from] PyQLTypeError),
36 #[error(transparent)]
37 Resolution(#[from] PyQLResolutionError),
38 #[error(transparent)]
39 Cardinality(#[from] PyQLCardinalityError),
40 #[error(transparent)]
41 Fragment(#[from] PyQLFragmentError),
42}
43
44impl PyQLError {
45 pub fn class_name_message_position(&self) -> (&'static str, &str, &Position) {
50 use PyQLError as E;
51 use PyQLResolutionError as R;
52 match self {
53 E::Syntax(e) => ("InvalidQueryError", &e.message, &e.position),
54 E::Type(e) => ("InvalidQueryError", &e.message, &e.position),
55 E::Resolution(R::UnknownType(e)) => ("UnknownTypeError", &e.message, &e.position),
56 E::Resolution(R::UnknownField(e)) => ("UnknownLinkError", &e.message, &e.position),
57 E::Resolution(R::UnknownParameter(e)) => ("UnknownParameterError", &e.message, &e.position),
58 E::Cardinality(e) => ("InvalidQueryError", &e.message, &e.position),
59 E::Fragment(e) => ("SchemaError", &e.message, &e.position),
60 }
61 }
62}
63
64#[derive(Debug, Error, Clone)]
65#[error("{message}")]
66pub struct PyQLSyntaxError {
67 pub message: String,
68 pub position: Position,
69}
70
71#[derive(Debug, Error, Clone)]
72#[error("{message}")]
73pub struct PyQLTypeError {
74 pub message: String,
75 pub position: Position,
76}
77
78#[derive(Debug, Error)]
80pub enum PyQLResolutionError {
81 #[error(transparent)]
82 UnknownType(#[from] PyQLUnknownTypeError),
83 #[error(transparent)]
84 UnknownField(#[from] PyQLUnknownFieldError),
85 #[error(transparent)]
86 UnknownParameter(#[from] PyQLUnknownParameterError),
87}
88
89#[derive(Debug, Error, Clone)]
90#[error("{message}")]
91pub struct PyQLUnknownTypeError {
92 pub message: String,
93 pub position: Position,
94}
95
96#[derive(Debug, Error, Clone)]
97#[error("{message}")]
98pub struct PyQLUnknownFieldError {
99 pub message: String,
100 pub position: Position,
101}
102
103#[derive(Debug, Error, Clone)]
104#[error("{message}")]
105pub struct PyQLUnknownParameterError {
106 pub message: String,
107 pub position: Position,
108}
109
110#[derive(Debug, Error, Clone)]
111#[error("{message}")]
112pub struct PyQLCardinalityError {
113 pub message: String,
114 pub position: Position,
115}
116
117#[derive(Debug, Error, Clone)]
118#[error("{message}")]
119pub struct PyQLFragmentError {
120 pub message: String,
121 pub position: Position,
122 pub context: String,
124}
125
126#[derive(Debug, Error)]
129pub enum PylonExecutionError {
130 #[error(transparent)]
131 ConstraintViolation(#[from] PylonConstraintViolationError),
132 #[error(transparent)]
133 CardinalityViolation(#[from] PylonCardinalityViolationError),
134 #[error(transparent)]
135 MissingRequired(#[from] PylonMissingRequiredError),
136 #[error(transparent)]
137 InvalidValue(#[from] PylonInvalidValueError),
138}
139
140#[derive(Debug, Error, Clone)]
141#[error("{message}")]
142pub struct PylonConstraintViolationError {
143 pub message: String,
144}
145
146#[derive(Debug, Error, Clone)]
147#[error("{message}")]
148pub struct PylonCardinalityViolationError {
149 pub message: String,
150}
151
152#[derive(Debug, Error, Clone)]
153#[error("{message}")]
154pub struct PylonMissingRequiredError {
155 pub message: String,
156}
157
158#[derive(Debug, Error, Clone)]
159#[error("{message}")]
160pub struct PylonInvalidValueError {
161 pub message: String,
162}