-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptions.py
More file actions
104 lines (71 loc) · 2.67 KB
/
exceptions.py
File metadata and controls
104 lines (71 loc) · 2.67 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""JSONPath exceptions."""
from __future__ import annotations
from typing import TYPE_CHECKING
from typing import Optional
if TYPE_CHECKING:
from .tokens import Token
class JSONPathError(Exception):
"""Base exception for all errors.
Arguments:
args: Arguments passed to `Exception`.
token: The token that caused the error.
"""
def __init__(self, *args: object, token: Optional[Token] = None) -> None:
super().__init__(*args)
self.token: Optional[Token] = token
def __str__(self) -> str:
msg = super().__str__()
if not self.token:
return msg
# TODO: Pretty error messages with current line and visual pointer.
line, column = self.token.position()
return f"{msg}, line {line}, column {column}"
class JSONPathSyntaxError(JSONPathError):
"""An exception raised when a error occurs during JSONPath expression parsing.
Arguments:
args: Arguments passed to `Exception`.
token: The token that caused the error.
"""
def __init__(self, *args: object, token: Token) -> None:
super().__init__(*args)
self.token = token
class JSONPathTypeError(JSONPathError):
"""An exception raised due to a type error.
This should only occur at when evaluating filter expressions.
"""
class JSONPathIndexError(JSONPathError):
"""An exception raised when an array index is out of range.
Arguments:
args: Arguments passed to `Exception`.
token: The token that caused the error.
"""
def __init__(self, *args: object, token: Token) -> None:
super().__init__(*args)
self.token = token
class JSONPathNameError(JSONPathError):
"""An exception raised when an unknown function extension is called.
Arguments:
args: Arguments passed to `Exception`.
token: The token that caused the error.
"""
def __init__(self, *args: object, token: Token) -> None:
super().__init__(*args)
self.token = token
class JSONPathLexerError(JSONPathError):
"""An exception raised from inside the lexer.
Arguments:
args: Arguments passed to `Exception`.
token: The token that caused the error.
"""
def __init__(self, *args: object, token: Token) -> None:
super().__init__(*args)
self.token = token
class JSONPathRecursionError(JSONPathError):
"""An exception raised when the maximum recursion depth is reached.
Arguments:
args: Arguments passed to `Exception`.
token: The token that caused the error.
"""
def __init__(self, *args: object, token: Token) -> None:
super().__init__(*args)
self.token = token