Let a `rescue_from` handler propagate an exception instead of rendering it
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Ruby
- スター
- 10k
- フォーク
- 1.2k
- 平均マージ
- 13時間 13分
- マージ済み PR(30日)
- 115
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby-grape/grape のほかの issue
-
feature request you can help
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
ruby-grape/grape#2487 · コメント 2 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ruby-grape/grape#2979 · コメント 1 件 ·
-
chore
難易度 2/5 1〜3時間 初心者へのやさしさ 30/100
ruby-grape/grape#2562 · コメント 4 件 ·
-
feature request
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
ruby-grape/grape#2522 · コメント 3 件 ·
-
bug?
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
ruby-grape/grape#2473 · コメント 6 件 · リアクション 1 件 ·
ruby-grape/grape の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
hanami/hanami-cli#449 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
resque/resque-scheduler#826 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100