Repository navigation
Restore the Error middleware's two defaults without restating every option - #3030
Merged
Merged
Conversation
ericproulx
force-pushed
the
refactor/error-middleware-options
branch
from
October 10, 2026 23:12
ad3a9d6 to
79141d3
Compare
Danger ReportNo issues found. |
…ption Middleware::Error::Options restores the defaults of rescue_options and default_error_formatter, which arrive as an explicit nil when the API called no rescue_from and no format. It did so with a super call that named all fourteen options again, a third list of them after the members and the keyword parameters. The two parameters are now reassigned and handed over by a bare super, which passes parameters as they stand. The comment no longer points at the def_delegator that #initialize stopped using. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
force-pushed
the
refactor/error-middleware-options
branch
from
October 11, 2026 08:17
79141d3 to
23e5718
Compare
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.
Middleware::Error::Optionslists its fourteen options asDatamembers and again as keyword parameters with their defaults. Two of them,rescue_optionsanddefault_error_formatter, arrive as an explicitnilfromEndpoint#error_middleware_optionswhen the API called norescue_fromand noformat. An explicitnilbypasses a keyword default, soinitializerestored the two by hand, in asupercall that named all fourteen options a third time.Change
A bare
superpasses the method's parameters as they stand, reassigned ones included. Checked on Ruby 4.0.7: explicitnils for the other options still go through asnil, an unknown keyword still raises, and positional construction and#withstill work. The comment no longer points at thedef_delegator :rescue_options, :backtracethat#initializereplaced with an instance variable.Not changed: the readers and the instance-variable copy
The middleware lists the options twice more, in
attr_readerand in the assignments in#initialize. Both could come fromOptions.members, but a loop costs build time. Copying throughinstance_variable_setmadeError.new43% slower in the interpreter and 49% with YJIT. With the instance-variable names precomputed and the values read offoptions, it was still 14% and 23% slower. Compiling a 200-route API was 1.7% and 2.8% slower in every run. Generating the assignments withclass_evalwould cost nothing, but Grape has no string-eval code generation, and a tidy-up is not a reason to introduce it. The lists stay written out.Tests
No spec changes; behaviour is unchanged.
bundle exec rakepasses.rescue_options, 34 withoutdefault_error_formatter.ErrorandFormatterbare, with explicitnils and with every option set, on master and on this branch. It dumped instance variables (names and order), reader values and#options; the dumps are identical.Error.newthroughput, master vs branch run alternately, two rounds: interpreter 350k → 355k, YJIT 480k → 464k. Master's own two YJIT rounds were 461k and 500k, so this is noise.🤖 Generated with Claude Code