Skip to content

Commit b9c2bf6

Browse files
committed
Catch more generic Lark exception per @coderabbitai
1 parent a29a5a4 commit b9c2bf6

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/undate/converters/calendars/gregorian/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from calendar import monthrange, isleap
22

3-
from lark.exceptions import UnexpectedCharacters
3+
from lark.exceptions import UnexpectedInput
44

55
from undate.undate import Undate
66
from undate.converters.base import BaseCalendarConverter
@@ -107,5 +107,5 @@ def parse(self, value: str) -> Undate:
107107
# set the original date string as the label
108108
undate_obj.label = value
109109
return undate_obj
110-
except UnexpectedCharacters as err:
110+
except UnexpectedInput as err:
111111
raise ValueError(f"Could not parse '{value}' as a Gregorian date") from err

src/undate/converters/calendars/hebrew/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Union
22

33
from convertdate import hebrew # type: ignore
4-
from lark.exceptions import UnexpectedCharacters
4+
from lark.exceptions import UnexpectedInput
55

66
from undate import Undate, UndateInterval
77
from undate.converters.base import BaseCalendarConverter
@@ -111,7 +111,7 @@ def parse(self, value: str) -> Union[Undate, UndateInterval]:
111111
# set the original date as a label, with the calendar name
112112
undate_obj.label = f"{value} {self.calendar_name}"
113113
return undate_obj
114-
except UnexpectedCharacters as err:
114+
except UnexpectedInput as err:
115115
raise ValueError(f"Could not parse '{value}' as a Hebrew date") from err
116116

117117
# do we need to support conversion the other direction?

src/undate/converters/calendars/islamic/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Union
22

33
from convertdate import islamic # type: ignore
4-
from lark.exceptions import UnexpectedCharacters
4+
from lark.exceptions import UnexpectedInput
55

66
from undate import Undate, UndateInterval
77
from undate.converters.base import BaseCalendarConverter
@@ -97,7 +97,7 @@ def parse(self, value: str) -> Union[Undate, UndateInterval]:
9797
# set the original date as a label, with the calendar name
9898
undate_obj.label = f"{value} {self.calendar_name}"
9999
return undate_obj
100-
except UnexpectedCharacters as err:
100+
except UnexpectedInput as err:
101101
raise ValueError(f"Could not parse '{value}' as an Islamic date") from err
102102

103103
# do we need to support conversion the other direction?

src/undate/converters/combined.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Union
88

99
from lark import Lark
10-
from lark.exceptions import UnexpectedCharacters
10+
from lark.exceptions import UnexpectedInput
1111
from lark.visitors import Transformer, merge_transformers
1212

1313
from undate import Undate, UndateInterval
@@ -77,7 +77,7 @@ def parse(self, value: str) -> Union[Undate, UndateInterval]:
7777
parsetree = parser.parse(value)
7878
# transform returns a list; we want the first item in the list
7979
return self.transformer.transform(parsetree)[0]
80-
except UnexpectedCharacters:
80+
except UnexpectedInput:
8181
raise ValueError(
8282
"Parsing failed: '%s' is not in a recognized date format" % value
8383
)

src/undate/converters/edtf/converter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional, Union
22

3-
from lark.exceptions import UnexpectedCharacters
3+
from lark.exceptions import UnexpectedInput
44

55
from undate import Undate, UndateInterval
66
from undate.converters.base import BaseDateConverter
@@ -40,10 +40,10 @@ def parse(self, value: str) -> Union[Undate, UndateInterval]:
4040
try:
4141
parsetree = edtf_parser.parse(value)
4242
return self.transformer.transform(parsetree)
43-
except UnexpectedCharacters:
43+
except UnexpectedInput as err:
4444
raise ValueError(
45-
"Parsing failed: '%s' is not a supported EDTF date format" % value
46-
)
45+
f"Parsing failed: '{value}' is not a supported EDTF date format"
46+
) from err
4747

4848
def _convert_missing_digits(
4949
self, value: Optional[str], old_missing_digit: str

0 commit comments

Comments
 (0)