-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
syntax_error.rs
78 lines (75 loc) · 2.54 KB
/
syntax_error.rs
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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
use thiserror::Error;
use crate::lexer::TokenKind;
#[derive(
Clone,
Copy,
Debug,
Error,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
serde::Serialize
)]
#[serde(tag = "type")]
pub enum SyntaxError {
#[error("Expected a {0}")]
Expected(TokenKind),
#[error("Expected a selection: field, inline fragment, or fragment spread")]
ExpectedSelection,
#[error("Expected a fragment, mutation, query, or subscription definition")]
ExpectedDefinition,
#[error("Expected a definition")]
ExpectedExecutableDefinition,
#[error("Expected a 'mutation', 'query', or 'subscription' keyword")]
ExpectedOperationKind,
#[error(
"Expected a valid variable name after $ (alphabetic character followed by any number of alphabetic, number and _ characters)"
)]
ExpectedVariableIdentifier,
#[error("Expected the keyword '{0}'")]
ExpectedKeyword(&'static str),
#[error("Expected a constant value (boolean, integer, float, string, null, list, or object")]
ExpectedConstantValue,
#[error("Expected a type annotation (e.g. '<Type>', '[Type]', 'Type!', etc)")]
ExpectedTypeAnnotation,
#[error(
"Expected a value ('$example', boolean, integer, float, string, null, list, or object)"
)]
ExpectedValue,
#[error("Expected a variable ('$example')")]
ExpectedVariable,
#[error("Expected a spread ('...')")]
ExpectedSpread,
#[error("Expected an argument")]
ExpectedArgument,
#[error("Expected the list to be non-empty")]
ExpectedNonEmptyList,
#[error("Invalid floating point value")]
InvalidFloat,
#[error("Invalid integer value")]
InvalidInteger,
#[error("Invalid number value, expected an int or float")]
InvalidNumberLiteral,
#[error(
"Invalid float literal, fractional float literals require a leading 0, e.g. 0.5 instead of .5"
)]
InvalidFloatLiteralMissingZero,
#[error("Invalid float value, GraphQL requires a leading zero, eg. 0.56")]
InvalidFloatMissingZeroLiteral,
#[error("Unsupported character")]
UnsupportedCharacter,
#[error("String containing an invalid character")]
UnsupportedStringCharacter,
#[error("Unterminated string literal (strings cannot contain unescaped line breaks)")]
UnterminatedString,
#[error("Unterminated block string literal")]
UnterminatedBlockString,
}