Nicer error message when unknown location specified in search query
This commit is contained in:
parent
0bbc2ad734
commit
8a9306d1bf
1 changed files with 11 additions and 2 deletions
|
|
@ -123,6 +123,15 @@ class Token(NamedTuple):
|
|||
REPLACEMENTS = tuple(('\\' + x, chr(i + 1)) for i, x in enumerate('\\"()'))
|
||||
|
||||
|
||||
class NoLocation(ParseException):
|
||||
|
||||
def __init__(self, tt: str):
|
||||
a, sep, b = tt.partition(':')
|
||||
if sep == ':':
|
||||
super().__init__(f'{a} is not a recognized location in {tt}')
|
||||
else:
|
||||
super().__init__(f'No location specified before {tt}')
|
||||
|
||||
class Parser:
|
||||
|
||||
def __init__(self, allow_no_location: bool = False) -> None:
|
||||
|
|
@ -225,7 +234,7 @@ def base_token(self) -> SearchTreeNode:
|
|||
assert tt is not None
|
||||
if self.allow_no_location:
|
||||
return TokenNode('all', tt)
|
||||
raise ParseException(f'No location specified before {tt}')
|
||||
raise NoLocation(tt)
|
||||
|
||||
tt = self.token(advance=True)
|
||||
assert tt is not None
|
||||
|
|
@ -253,7 +262,7 @@ def base_token(self) -> SearchTreeNode:
|
|||
|
||||
if self.allow_no_location:
|
||||
return TokenNode('all', ':'.join(words))
|
||||
raise ParseException(f'No location specified before {tt}')
|
||||
raise NoLocation(tt)
|
||||
|
||||
|
||||
@lru_cache(maxsize=64)
|
||||
|
|
|
|||
Loading…
Reference in a new issue