graphql_query/schema/sdl/
error.rs1use std::{error::Error, fmt::Display};
2
3#[derive(Debug)]
5pub enum SchemaError {
6 SyntaxError(String),
7 ValidationError(String),
8}
9
10impl Display for SchemaError {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 match self {
13 SchemaError::SyntaxError(s) => write!(f, "{}", s),
14 SchemaError::ValidationError(s) => write!(f, "Validation error: {}", s),
15 }
16 }
17}
18
19impl Error for SchemaError {}
20
21macro_rules! syntax_err {
22 ($msg:literal, $($arg:tt)*) => {
23 Err(syntax!($msg, $($arg)*))
24 };
25
26 ($msg:literal) => {
27 Err(syntax!($msg))
28 };
29}
30
31macro_rules! syntax {
32 ($msg:literal, $($arg:tt)*) => {
33 SchemaError::SyntaxError(format!($msg, $($arg)*))
34 };
35
36 ($msg:literal) => {
37 SchemaError::SyntaxError(format!($msg))
38 };
39}
40
41macro_rules! validation {
42 ($msg:literal, $($arg:tt)*) => {
43 SchemaError::ValidationError(format!($msg, $($arg)*))
44 };
45
46 ($msg:literal) => {
47 SchemaError::ValidationError(format!($msg))
48 };
49}
50
51pub(crate) use syntax;
53pub(crate) use syntax_err;
54pub(crate) use validation;