Skip to content

Unhandled keyword arguments for attaching middleware #2544

@yungtrizzle

Description

@yungtrizzle

Upgrading a rails 6.1 app to ruby 3.3 and noticing a weird bug on using middleware. Somehow the keyword argument drops before getting to Rack Builder.

Somewhat related is #2257 and especially the last comment #2257 (comment) which is what my code looks like as well:

use ActionDispatch::RequestId, header: "X-Request-Id"

I'm not sure if this due to rails 6.1 pinning to rack 2.x but seems weird.

Stacktrack:

[test] [2025-03-05 09:42:54.930] [sg.test] [E] {"message":null,"exception":"wrong number of arguments (given 2, expected 1; required keyword: header)","extra":{"use_exception_level_filters":"true"},"context":null}
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/request_id.rb:18:in `initialize'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/builder.rb:158:in `new'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/builder.rb:158:in `block in use'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/builder.rb:235:in `block in to_app'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/builder.rb:235:in `each'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/builder.rb:235:in `inject'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/builder.rb:235:in `to_app'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/endpoint.rb:410:in `build_stack'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/endpoint.rb:302:in `block in lazy_initialize!'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/endpoint.rb:298:in `synchronize'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/endpoint.rb:298:in `lazy_initialize!'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/endpoint.rb:215:in `call'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router/route.rb:27:in `exec'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router.rb:121:in `process_route'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router.rb:68:in `block in identity'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router.rb:101:in `transaction'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router.rb:66:in `identity'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router.rb:50:in `block in call'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router.rb:137:in `with_optimization'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/router.rb:49:in `call'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/api/instance.rb:164:in `call'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/api/instance.rb:68:in `call!'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/api/instance.rb:63:in `call'
/usr/local/bundle/gems/grape-2.3.0/lib/grape/api.rb:78:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/routing/mapper.rb:20:in `block in <class:Constraints>'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/routing/mapper.rb:49:in `serve'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/journey/router.rb:50:in `block in serve'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/journey/router.rb:32:in `each'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/journey/router.rb:32:in `serve'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/routing/route_set.rb:842:in `call'
/usr/local/bundle/gems/flipper-1.3.2/lib/flipper/middleware/memoizer.rb:87:in `memoized_call'
/usr/local/bundle/gems/flipper-1.3.2/lib/flipper/middleware/memoizer.rb:45:in `call'
/usr/local/bundle/gems/bullet-8.0.0/lib/bullet/rack.rb:14:in `call'
/usr/local/bundle/gems/rack-attack-6.7.0/lib/rack/attack.rb:103:in `call'
/myapp/config/initializers/strip_x_forwarded_host.rb:21:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/session/abstract/id.rb:266:in `context'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/session/abstract/id.rb:260:in `call'
/myapp/app/domains/metrics/metrics_collection_middleware.rb:91:in `call_with_timing'
/myapp/app/domains/metrics/metrics_collection_middleware.rb:8:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/session/abstract/id.rb:266:in `context'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/session/abstract/id.rb:260:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/cookies.rb:697:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/method_override.rb:24:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/deflater.rb:44:in `call'
/usr/local/bundle/gems/remotipart-1.4.4/lib/remotipart/middleware.rb:32:in `call'
/usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
/usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
/usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/etag.rb:27:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/conditional_get.rb:40:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/head.rb:12:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
/usr/local/bundle/gems/activesupport-6.1.7.10/lib/active_support/callbacks.rb:98:in `run_callbacks'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/executor.rb:14:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
/usr/local/bundle/gems/rollbar-3.6.1/lib/rollbar/middleware/rails/rollbar.rb:25:in `block in call'
/usr/local/bundle/gems/rollbar-3.6.1/lib/rollbar.rb:145:in `scoped'
/usr/local/bundle/gems/rollbar-3.6.1/lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
/usr/local/bundle/gems/rollbar-3.6.1/lib/rollbar/middleware/rails/show_exceptions.rb:27:in `call_with_rollbar'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
/usr/local/bundle/gems/lograge-0.14.0/lib/lograge/rails_ext/rack/logger.rb:18:in `call_app'
/usr/local/bundle/gems/railties-6.1.7.10/lib/rails/rack/logger.rb:28:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
/usr/local/bundle/gems/request_store-1.7.0/lib/request_store/middleware.rb:19:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/request_id.rb:26:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/runtime.rb:22:in `call'
/usr/local/bundle/gems/activesupport-6.1.7.10/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/executor.rb:14:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/static.rb:24:in `call'
/usr/local/bundle/gems/rack-2.2.10/lib/rack/sendfile.rb:110:in `call'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/middleware/host_authorization.rb:142:in `call'
/usr/local/bundle/gems/rack-cors-2.0.2/lib/rack/cors.rb:102:in `call'
/usr/local/bundle/gems/railties-6.1.7.10/lib/rails/engine.rb:539:in `call'
/usr/local/bundle/gems/rack-test-2.2.0/lib/rack/test.rb:360:in `process_request'
/usr/local/bundle/gems/rack-test-2.2.0/lib/rack/test.rb:153:in `request'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/testing/integration.rb:279:in `process'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/testing/integration.rb:22:in `post'
/usr/local/bundle/gems/actionpack-6.1.7.10/lib/action_dispatch/testing/integration.rb:372:in `post'
/usr/local/bundle/gems/rails-controller-testing-1.0.5/lib/rails/controller/testing/integration.rb:16:in `block (2 levels) in <module:Integration>'
/myapp/spec/controllers/api/grape_v4/disbursements/singapore/disbursements_api_spec.rb:78:in `block (6 levels) in <main>'
<internal:numeric>:237:in `times'
/myapp/spec/controllers/api/grape_v4/disbursements/singapore/disbursements_api_spec.rb:77:in `block (5 levels) in <main>'
/usr/local/bundle/gems/rspec-expectations-3.13.3/lib/rspec/matchers/built_in/change.rb:395:in `perform_change'
/usr/local/bundle/gems/rspec-expectations-3.13.3/lib/rspec/matchers/built_in/change.rb:146:in `matches?'
/usr/local/bundle/gems/rspec-expectations-3.13.3/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
/usr/local/bundle/gems/rspec-expectations-3.13.3/lib/rspec/expectations/handler.rb:26:in `with_matcher'
/usr/local/bundle/gems/rspec-expectations-3.13.3/lib/rspec/expectations/handler.rb:47:in `handle_matcher'
/usr/local/bundle/gems/rspec-expectations-3.13.3/lib/rspec/expectations/expectation_target.rb:65:in `to'
/usr/local/bundle/gems/rspec-expectations-3.13.3/lib/rspec/expectations/expectation_target.rb:139:in `to'
/myapp/spec/controllers/api/grape_v4/disbursements/singapore/disbursements_api_spec.rb:76:in `block (4 levels) in <main>'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:263:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:263:in `block in run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:511:in `block in with_around_and_singleton_context_hooks'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:468:in `block in with_around_example_hooks'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:486:in `block in run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:352:in `call'
/usr/local/bundle/gems/rspec-rails-6.1.5/lib/rspec/rails/adapters.rb:75:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:390:in `execute_with'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:352:in `call'
/usr/local/bundle/gems/webmock-3.25.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:390:in `execute_with'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:352:in `call'
/usr/local/bundle/gems/vcr-6.3.1/lib/vcr/util/variable_args_block_caller.rb:9:in `call_block'
/usr/local/bundle/gems/vcr-6.3.1/lib/vcr.rb:194:in `use_cassette'
/myapp/spec/support/config/gems/vcr.rb:70:in `block (2 levels) in <main>'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:390:in `execute_with'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:352:in `call'
/usr/local/bundle/gems/rspec-retry-0.6.2/lib/rspec/retry.rb:124:in `block in run'
<internal:kernel>:187:in `loop'
/usr/local/bundle/gems/rspec-retry-0.6.2/lib/rspec/retry.rb:110:in `run'
/usr/local/bundle/gems/rspec-retry-0.6.2/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
/usr/local/bundle/gems/rspec-retry-0.6.2/lib/rspec/retry.rb:37:in `block (2 levels) in setup'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:457:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:390:in `execute_with'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:352:in `call'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/hooks.rb:486:in `run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example.rb:259:in `run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:646:in `block in run_examples'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:642:in `map'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:642:in `run_examples'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:607:in `run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:608:in `block in run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:608:in `map'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:608:in `run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:608:in `block in run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:608:in `map'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/example_group.rb:608:in `run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:121:in `map'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/configuration.rb:2097:in `with_suite_hooks'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:116:in `block in run_specs'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/reporter.rb:74:in `report'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:115:in `run_specs'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:89:in `run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:71:in `run'
/usr/local/bundle/gems/rspec-core-3.13.3/lib/rspec/core/runner.rb:45:in `invoke'
/usr/local/bundle/gems/rspec-core-3.13.3/exe/rspec:4:in `<top (required)>'
/usr/local/bundle/bin/rspec:25:in `load'
/usr/local/bundle/bin/rspec:25:in `<top (required)>'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/cli/exec.rb:59:in `load'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/cli/exec.rb:59:in `kernel_load'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/cli/exec.rb:23:in `run'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/cli.rb:452:in `exec'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor.rb:538:in `dispatch'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/cli.rb:35:in `dispatch'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/cli.rb:29:in `start'
/usr/local/bundle/gems/bundler-2.6.3/exe/bundle:28:in `block in <top (required)>'
/usr/local/bundle/gems/bundler-2.6.3/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/usr/local/bundle/gems/bundler-2.6.3/exe/bundle:20:in `<top (required)>'
/usr/local/bundle/bin/bundle:25:in `load'
/usr/local/bundle/bin/bundle:25:in `<main>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions