Skip to content

_parse_timedelta: raise options.Error with the offending value#3665

Open
HrachShah wants to merge 1 commit into
tornadoweb:masterfrom
HrachShah:fix/options-parse-timedelta-bare-exception
Open

_parse_timedelta: raise options.Error with the offending value#3665
HrachShah wants to merge 1 commit into
tornadoweb:masterfrom
HrachShah:fix/options-parse-timedelta-bare-exception

Conversation

@HrachShah

Copy link
Copy Markdown

The previous code raised a bare Exception() (no message, no type info) when the timedelta pattern failed to match, then wrapped the whole body in try/except Exception: raise which is a no-op. A bare Exception() gives no hint about what failed; downstream code that catches options.Error (the rest of the module) would not see the failure, and the user would get 'Exception:' with no message at all.

Replace raise Exception() with raise Error("Invalid time delta: %r" % value) (matching the style of _parse_datetime's "Unrecognized date/time format") and drop the try/except: raise wrapper so genuine programming errors surface normally.

Added test_parse_timedelta_invalid_raises_options_error in tornado/test/options_test.py covers --foo=xyz; the test fails on the pre-fix code (raises Exception, not Error) and passes with the fix. All 25 options tests pass.

The previous code raised a bare 'Exception()' (no message, no type info)
when the timedelta pattern failed to match, then wrapped the whole body
in 'try/except Exception: raise' which is a no-op. A bare Exception()
gives no hint about what failed; downstream code that catches
options.Error (the rest of the module) would not see the failure, and
the user would get 'Exception:' with no message at all.

Replace 'raise Exception()' with 'raise Error("Invalid time delta: %r"
% value)' (matching the style of _parse_datetime's
'Unrecognized date/time format') and drop the try/except: raise wrapper
so genuine programming errors surface normally.

Added test_parse_timedelta_invalid_raises_options_error in
tornado/test/options_test.py covers --foo=xyz; the test fails on the
pre-fix code (raises Exception, not Error) and passes with the fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant