Rescue TypeError in date/time and numeric filter converters - #595
Draft
justincampbell wants to merge 1 commit into
Draft
Rescue TypeError in date/time and numeric filter converters#595justincampbell wants to merge 1 commit into
justincampbell wants to merge 1 commit into
Conversation
AbstractDateTimeFilter#convert_string and AbstractNumericFilter#safe_converter only rescued ArgumentError. When an input object's to_str / to_int returns a non-String / non-Integer (violating the implicit-conversion contract but legal Ruby), the underlying parse raises TypeError, which escapes the filter and propagates out of .run as an unhandled exception — violating the contract that .run returns a result with errors rather than raising for bad input. Rescue TypeError alongside ArgumentError so these values surface as :invalid_type filter errors, consistent with other unparseable inputs.
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.
Problem
AbstractDateTimeFilter#convert_stringandAbstractNumericFilter#safe_converteronly rescueArgumentError. When an input object hasto_str/to_intthat returns a non-String / non-Integer (legal Ruby, though it violates the implicit-conversion contract), the underlying parse raisesTypeError, which escapes the filter and propagates out of.runas an unhandled exception:This breaks the contract that
.runreturns a result — even for bad input, it should surface a validation error, not raise. The same pattern exists inAbstractNumericFilter#safe_converterwhereInteger(non_int)/Float(non_str)/BigDecimal(non_str)raiseTypeErrorthat isn't caught.Fix
Rescue
TypeErroralongsideArgumentErrorin both filters, so non-conformingto_str/to_intvalues surface as:invalid_typefilter errors — consistent with how unparseable strings are already handled.Test plan
date_filter_spec.rbandinteger_filter_spec.rbthat construct values with ato_strreturning a Symbol. Both specs fail onmainwith uncaughtTypeErrorand pass with this change.bundle exec rspecsuite passes (1088 examples, 0 failures).Marking draft while maintainers review the approach.