Skip to content

Make rescue_from reject meta selectors mixed with exception classes#2737

Open
ericproulx wants to merge 1 commit into
masterfrom
refactor/rescue-from-explicit-first-arg
Open

Make rescue_from reject meta selectors mixed with exception classes#2737
ericproulx wants to merge 1 commit into
masterfrom
refactor/rescue-from-explicit-first-arg

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

@ericproulx ericproulx commented May 23, 2026

Summary

  • rescue_from previously accepted *args and short-circuited on if args.include?(:all) (and the same for :grape_exceptions / :internal_grape_exceptions), silently dropping any exception classes passed alongside the meta selector. rescue_from :all, MyError, with: :h would only register the :all handler — MyError never bound.
  • Keep the existing *args signature, add a single guard above the dispatch: if any meta selector is present and args.size > 1, raise ArgumentError.
  • Valid forms unchanged: rescue_from :all, rescue_from :all, with: :h, rescue_from :all, &block, rescue_from MyError, OtherError, with: :h, etc.

Contract change

Mixing a meta selector with exception classes now raises ArgumentError instead of silently ignoring the classes. UPGRADING entry added.

Test plan

  • bundle exec rspec — 2316 examples, 0 failures (3 new ArgumentError specs)
  • bundle exec rubocop — clean on touched files
  • CI green

🤖 Generated with Claude Code

@ericproulx ericproulx force-pushed the refactor/rescue-from-explicit-first-arg branch from 1abf26f to d6db7de Compare May 23, 2026 11:31
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 23, 2026

Danger Report

No issues found.

View run

@ericproulx ericproulx force-pushed the refactor/rescue-from-explicit-first-arg branch 2 times, most recently from 5d40407 to 01cebc9 Compare May 23, 2026 11:38
Previously the `*args` signature meant that:

  rescue_from :all, MyError, with: :handler

silently dropped `MyError`: the `if args.include?(:all)` branch fired
and the trailing argument was never registered. Same for
`:grape_exceptions` and `:internal_grape_exceptions`.

Keep the existing `*args` signature, add a single guard above the
dispatch: if any meta selector is present and `args.size > 1`, raise
`ArgumentError`. Valid forms (`rescue_from :all`,
`rescue_from :all, with:`, `rescue_from MyError, OtherError, with:`)
are unaffected.

CHANGELOG + UPGRADING entries added; three new request_response_spec
examples cover the new ArgumentError contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the refactor/rescue-from-explicit-first-arg branch from 01cebc9 to 34a5f78 Compare May 23, 2026 16:32
@ericproulx ericproulx requested a review from dblock May 23, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants