_parse_timedelta: raise options.Error with the offending value#3665
Open
HrachShah wants to merge 1 commit into
Open
_parse_timedelta: raise options.Error with the offending value#3665HrachShah wants to merge 1 commit into
HrachShah wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous code raised a bare
Exception()(no message, no type info) when the timedelta pattern failed to match, then wrapped the whole body intry/except Exception: raisewhich 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()withraise 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_errorin tornado/test/options_test.py covers--foo=xyz; the test fails on the pre-fix code (raisesException, notError) and passes with the fix. All 25 options tests pass.