mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 18:22:09 +02:00
Nicer error message when unknown location specified in search query
This commit is contained in:
@@ -123,6 +123,15 @@ lex_scanner = getattr(re, 'Scanner')([
|
|||||||
REPLACEMENTS = tuple(('\\' + x, chr(i + 1)) for i, x in enumerate('\\"()'))
|
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:
|
class Parser:
|
||||||
|
|
||||||
def __init__(self, allow_no_location: bool = False) -> None:
|
def __init__(self, allow_no_location: bool = False) -> None:
|
||||||
@@ -225,7 +234,7 @@ class Parser:
|
|||||||
assert tt is not None
|
assert tt is not None
|
||||||
if self.allow_no_location:
|
if self.allow_no_location:
|
||||||
return TokenNode('all', tt)
|
return TokenNode('all', tt)
|
||||||
raise ParseException(f'No location specified before {tt}')
|
raise NoLocation(tt)
|
||||||
|
|
||||||
tt = self.token(advance=True)
|
tt = self.token(advance=True)
|
||||||
assert tt is not None
|
assert tt is not None
|
||||||
@@ -253,7 +262,7 @@ class Parser:
|
|||||||
|
|
||||||
if self.allow_no_location:
|
if self.allow_no_location:
|
||||||
return TokenNode('all', ':'.join(words))
|
return TokenNode('all', ':'.join(words))
|
||||||
raise ParseException(f'No location specified before {tt}')
|
raise NoLocation(tt)
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=64)
|
@lru_cache(maxsize=64)
|
||||||
|
|||||||
Reference in New Issue
Block a user