Show real cause of ActionView::Template::Error with Rails 6 #477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #459 we stopped always showing the
causeof an exception. This backs that out a bit by adding a special case forActionView::Template::Errorprovided by Rails 6. This should solve the incorrect backtrace in that case.Here's how this came to be:
ActionView::Template::Errorto display its#original_exceptioninstead of the top-level error.original_exceptionregardless of the exception class. I'm not sure why this was done, but likely it's because there are errors similar toActionView::Template::Errorthat it's desirable for.Exception#causewhich provides a standard pattern for the thing that Rails was doing with#original_exception.#causejust like it had for errors that had an#original_exception.#causenow, where before it would follow#original_exceptiononly when Rails provided one, and Ruby exceptions frequently have a#causebut the top-level error is the informative one.Exception#causecompletely, but leave the older Rails#original_exceptionbehavior in place.#original_exceptionand instead started providing#cause, following the Ruby standard.ActionView::Template::Error, prepending a stack trace frame to the top-level exception so there's something to work with.ActionView::Template::Errorinstance only refers to the line in the template that was being executed when the exception was raised.So this change adds back the original, original behavior of treating
ActionView::Template::Erroras a special case, stripping off the top-level exception and showing its#cause. There might be other Rails errors that need to be treated this way. If you identify one please let us know!The behavior to support all old Rails exceptions, where it always follows the
#original_exceptionis still there.Fixes #466. Fixes #470.