Skip to content

Commit

Permalink
Fix TypeError in parser wrapper logic
Browse files Browse the repository at this point in the history
In attempting to pass-through the string representation of an exception
we are wrapping, we made the erroneous assumption that `args[0]` would
always be a string (or something that can concatenate cleanly with a
string). This turns out not to be the case with `IllegalMonthError`,
where it is an integer, so to avoid raising an erroneous `TypeError`, we
first convert the wrapped exception to a string.

See GH issue dateutil#981.
  • Loading branch information
eastface authored and pganssle committed Jan 2, 2020
1 parent f6c6d5c commit 79d2e48
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.d/987.bugfix.rst
@@ -0,0 +1,4 @@
Fixed a bug in the parser where non-``ValueError`` exceptions would be raised
during exception handling; this would happen, for example, if an
``IllegalMonthError`` was raised in ``dateutil`` code. Fixed by Mark Bailey.
(gh issue #981, pr #987).
2 changes: 1 addition & 1 deletion dateutil/parser/_parser.py
Expand Up @@ -654,7 +654,7 @@ def parse(self, timestr, default=None,
try:
ret = self._build_naive(res, default)
except ValueError as e:
six.raise_from(ParserError(e.args[0] + ": %s", timestr), e)
six.raise_from(ParserError(str(e) + ": %s", timestr), e)

if not ignoretz:
ret = self._build_tzaware(ret, res, tzinfos)
Expand Down
4 changes: 4 additions & 0 deletions dateutil/test/test_parser.py
Expand Up @@ -743,6 +743,10 @@ def test_out_of_bound_day(self):
with pytest.raises(ParserError):
parse("Feb 30, 2007")

def test_illegal_month_error(self):
with pytest.raises(ParserError):
parse("0-100")

def test_day_sanity(self, fuzzy):
dstr = "2014-15-25"
with pytest.raises(ParserError):
Expand Down

0 comments on commit 79d2e48

Please sign in to comment.