{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/33414","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/33414/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/33414/comments","events_url":"https://api.github.com/repos/rails/rails/issues/33414/events","html_url":"https://github.com/rails/rails/issues/33414","id":343388845,"node_id":"MDU6SXNzdWUzNDMzODg4NDU=","number":33414,"title":"In controller rescued error is shown if `rescue` clause raises","user":{"login":"SzNagyMisu","id":25562614,"node_id":"MDQ6VXNlcjI1NTYyNjE0","avatar_url":"https://avatars1.githubusercontent.com/u/25562614?v=4","gravatar_id":"","url":"https://api.github.com/users/SzNagyMisu","html_url":"https://github.com/SzNagyMisu","followers_url":"https://api.github.com/users/SzNagyMisu/followers","following_url":"https://api.github.com/users/SzNagyMisu/following{/other_user}","gists_url":"https://api.github.com/users/SzNagyMisu/gists{/gist_id}","starred_url":"https://api.github.com/users/SzNagyMisu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SzNagyMisu/subscriptions","organizations_url":"https://api.github.com/users/SzNagyMisu/orgs","repos_url":"https://api.github.com/users/SzNagyMisu/repos","events_url":"https://api.github.com/users/SzNagyMisu/events{/privacy}","received_events_url":"https://api.github.com/users/SzNagyMisu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-07-22T08:42:01Z","updated_at":"2018-07-22T16:30:35Z","closed_at":null,"author_association":"NONE","body":"### Steps to reproduce\r\n\r\n[repro](https://github.com/SzNagyMisu/rails-controller-error) (see branches `rails-5.1.6` and `rails-5.2.0`)\r\n\r\nIf I rescue an exception in a controller action (let's say, an `ActiveRecord::RecordInvalid` after a `.create!` or an `#update!`) and then in the `rescue` clause I raise another exception (by making a typo, for example), I get the **original (rescued) exception** in the response. So if I have\r\n\r\n    class BooksController < ApplicationController\r\n      def create\r\n        Book.create!(book_params)\r\n      rescue ActiveRecord::RecordInvalid\r\n        redirect_to new_book # sometimes I just forget the `_path` suffix\r\n      end\r\n    end\r\n\r\nin case the `book_params` contain insufficient or erroneous data, and an `ActiveRecord::RecordInvalid` exception is raised, the response contains the error message `ActiveRecord::RecordInvalid in BooksController#create`, and it points to the line `Book.create!(book_params)`.\r\n\r\nThen, a couple of hours of investigation show me, that I just forgot about the `_path` suffix of `#new_book_path` and it raises a `NameError`, which caused the action to collapse, only with the wrong error message.\r\n\r\nIn the **repro** I tried it against rails 5.1.6 and 5.2.0 (ruby 2.4.1). I tried to write tests for the expected behavior, but in _test environment_ this is exactly what I get: `NameError: undefined local variable or method ...`, so tests became meaningless.\r\n\r\nI tried it out in the rails console too, and found out that the problem exists in _development_ and _production_ mode but not in _test_.\r\n\r\n### Expected behavior\r\nThe action should show the **last exception** in the response, **not the rescued** one.\r\n\r\n### Actual behavior\r\nIn _development_ and _production_ mode, if the `rescue` clause raises, the **original (rescued) exception** is shown\r\n\r\n### System configuration\r\n**Rails version**: 5.x\r\n\r\n**Ruby version**: I don't think, it matters, but I'm using 2.4.1\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/406879564","html_url":"https://github.com/rails/rails/issues/33414#issuecomment-406879564","issue_url":"https://api.github.com/repos/rails/rails/issues/33414","id":406879564,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjg3OTU2NA==","user":{"login":"azbshiri","id":15009059,"node_id":"MDQ6VXNlcjE1MDA5MDU5","avatar_url":"https://avatars0.githubusercontent.com/u/15009059?v=4","gravatar_id":"","url":"https://api.github.com/users/azbshiri","html_url":"https://github.com/azbshiri","followers_url":"https://api.github.com/users/azbshiri/followers","following_url":"https://api.github.com/users/azbshiri/following{/other_user}","gists_url":"https://api.github.com/users/azbshiri/gists{/gist_id}","starred_url":"https://api.github.com/users/azbshiri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azbshiri/subscriptions","organizations_url":"https://api.github.com/users/azbshiri/orgs","repos_url":"https://api.github.com/users/azbshiri/repos","events_url":"https://api.github.com/users/azbshiri/events{/privacy}","received_events_url":"https://api.github.com/users/azbshiri/received_events","type":"User","site_admin":false},"created_at":"2018-07-22T16:30:35Z","updated_at":"2018-07-22T16:30:35Z","author_association":"CONTRIBUTOR","body":"@rafaelfranca how is that?"}}
{"actor":{"display_login":"azbshiri"}}