Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Let a `rescue_from` handler propagate an exception instead of rendering it

Aperta
#3,003 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rails, ruby
Ambito
api, backend

Direzione di ricerca

Look at the rescue_from handling in lib/grape/middleware/error.rb and lib/grape/dsl/inside_route.rb. Understand how exceptions are caught and redispatched since #2703. The change involves adding a propagate option to rescue_from, similar to the raise_rendering_errors config. Check existing tests for rescue_from to see how to add new behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Since #2703 (3.3.0) an exception raised inside a rescue_from block is caught and redispatched instead of escaping the middleware stack. That fixed #2482, and it also removed the only way an app could let a specific exception class reach Rack middleware mounted above Grape. There's no opt-out today.

The case I hit: Rails' ActiveRecord::Middleware::DatabaseSelector routes a request to a read replica, and a custom config.active_record.database_resolver can catch ActiveRecord::ReadOnlyError and retry the block against the primary. The app re-raised that error from rescue_from(:all) so the resolver upstream could do its job. On 3.3+ it no longer gets there, so the request 500s where it used to recover, and nothing notices, since the redispatch renders an ordinary 500.

env['grape.exception'] (#2855) is enough to report the exception but not to act on it, because the response is already built by then. Raising a non-StandardError does escape, but it bypasses every intervening rescue => e. Dropping rescue_from :all gives up the catch-all for everything else, and #2737 makes excluding a single class from it an ArgumentError.

#2840 made the same call for the rendering case and added Grape.config.raise_rendering_errors to opt back out. I'd like the equivalent for the handler case:

rescue_from ActiveRecord::ReadOnlyError, propagate: true

Verified the behavior above against 4.0.1. Happy to open a PR if the direction seems right.

Lingua principale
Ruby
Stelle
10k
Fork
1.2k
Merge medio
13h 13m
PR unite (30g)
115

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby-grape/grape

Tutte le issue di ruby-grape/grape

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.