Hand a Proc passed as the last middleware argument to the middleware - #2967
Merged
Merged
Conversation
ericproulx
force-pushed
the
fix/middleware-proc-argument
branch
from
September 19, 2026 19:19
6b11f86 to
2a048d4
Compare
The middleware DSL recorded a registration as [operation, *args] and
appended the block only when one was given, so Stack#merge_with told the
block apart by its class: whatever Proc came last was popped and passed
as the block. A callable handed to a middleware as its last argument,
as in `use SomeMiddleware, ->(env) { ... }`, was taken for the block
instead, and the middleware was built without it, raising ArgumentError
when the stack was built. `insert_before` and `insert_after` did the
same.
Every registration now ends in its block, nil when none was given, and
merge_with always takes the last element as the block. That changes the
entries `API.middleware` returns, hence the UPGRADING note.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ericproulx
force-pushed
the
fix/middleware-proc-argument
branch
from
September 19, 2026 19:37
2a048d4 to
9d85969
Compare
Danger ReportNo issues found. |
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.
Summary
A callable passed as the last argument to
use,insert_beforeorinsert_afterwas taken for the middleware's block:The DSL recorded a registration as
[operation, *args]and appended the block only when one was given, soStack#merge_withtold the block apart by its class and popped whatever Proc came last. The middleware was then built without its callable. Reproduced on 2.1.3, 3.0.1, 3.3.5 and 4.0.1; the pop dates from c2e41f7 (2016).Every registration now ends in its block,
nilwhen none was given, andmerge_withalways takes the last element as the block.Contract change
API.middlewarereturns those entries, so each one now ends innilwhen no block was given:Covered in UPGRADING. grape-swagger's own check (
middleware.flatten.include?(auth_wrapper)) is unaffected.Test plan
useandinsert_before, and a block given alongside it stays the block; the two argument cases fail without the fix.🤖 Generated with Claude Code