• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-grape / grape / 30695004210

01 Aug 2026 10:04AM UTC coverage: 96.97% (-0.006%) from 96.976%
30695004210

push

github

ericproulx
Let rescue_from :grape_exceptions outrank a catch-all class handler

rescue_from :grape_exceptions is an opt-in to keep Grape's own errors
rendering with their own status -- a validation failure answers 400 rather
than whatever the application's catch-all returns.

It only ever worked against rescue_from :all, which lives in
all_rescue_handler and is consulted last. Written as a class instead,
rescue_from StandardError is a registered handler, matched first, and Grape's
exceptions are StandardErrors -- so the opt-in silently did nothing and
validation errors still came back as 500s:

    rescue_from StandardError { error!('server error', 500) }
    rescue_from :grape_exceptions          # inert

Let the opt-in win over a handler that only matched through a non-Grape
ancestor. A handler registered for a Grape exception class is more precise
than the opt-in and still wins, so an explicit
rescue_from Grape::Exceptions::ValidationErrors keeps its handler.

registered_rescue_handler gains an _entry variant returning the matched class
alongside its handler, since deciding this needs to know *which* class matched,
not just that one did. find_handler resolves the entry once and passes it down.

Application errors still reach the catch-all, rescue_from :all is unchanged,
and InvalidVersionHeader is left alone so it keeps reaching Rack and version
cascading still works.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

1207 of 1297 branches covered (93.06%)

Branch coverage included in aggregate %.

3817 of 3884 relevant lines covered (98.27%)

26770.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/lib/grape/middleware/error.rb


Build SHA Not Found

The commit SHA "b39fbb472f487721d1302293b759b72688990329" was not found in your repository, so the file cannot be loaded. This may be because you posted from a local development environment, or your CI created an ephemeral commit.

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc