rails: Unable to rescue_from ActionDispatch::Http::Parameters::ParseError
Steps to reproduce
rails new bugreportrails g controller home- Add
rescue_fromin https://github.com/jeffblake/paramsparserbug/blob/master/app/controllers/home_controller.rb - See test case: https://github.com/jeffblake/paramsparserbug/blob/master/test/controllers/home_controller_test.rb
Bug repo here: https://github.com/jeffblake/paramsparserbug
Expected behavior
According to this pull request, https://github.com/rails/rails/pull/34341
rescuing from ActionDispatch::Http::Parameters::ParseError should be possible in the controller.
Actual behavior
ActionDispatch::Http::Parameters::ParseError is not caught by the rescue_from in the controller.
System configuration
Rails version: latest 6.0.2.1
Ruby version: 2.6.5
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 18 (9 by maintainers)
Commits related to this issue
- Fix handling of ParseError in controllers It regressed in #34894, which moved the rescue to the wrong method. `_wrapper_enabled?` can access the parameters and the exception will raise there before e... — committed to rails/rails by rafaelfranca 6 years ago
- Fix handling of ParseError in controllers It regressed in #34894, which moved the rescue to the wrong method. `_wrapper_enabled?` can access the parameters and the exception will raise there before e... — committed to rails/rails by rafaelfranca 6 years ago
Now it is fixed and the test take care of making sure this specific problem don’t have regressions.
It was broken by #34894. I’m fixing.
This is currently breaking our Middleware that was supposed to catch the
ParseErrors. The exception is no longer raised and just catched by https://github.com/wbotelhos/rails/commit/2cdf756808f43c9ee0ae2b83d4f06e93b8d9e763#diff-3834450d445e54f361a0cd4e9d6814c29d1279ca6dab4e99a0c88855e7689daeR287In order to fix that and make our Middleware work again, I overrode the method in the ApplicationController:
and removed the
rescueblock. Our middleware is now working again:Perhaps someone wants to re-open this issue? It seems that this still persists. Having to override proceed or introduce middleware seems silly considering this was previously acknowledged and addressed?
Ah sorry, it’s hard to decipher what changed overtime. Thank you for bringing this up. Let me drop this code snippet below so hopefully it helps the next person when they find this GitHub issue after a google search.
This resolves the issue on Rails 6.1.7
@rafaelfranca My bug report includes steps to reproduce and a sample repo with tests.
The special
rescue_fromhandling (introduced in PR #34341) no longer works, but @JoshCheek’s workaround still does.@jeffblake there is an existing workaround: https://github.com/rails/rails/issues/34244#issuecomment-433365579