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
cause
of an exception. This backs that out a bit by adding a special case forActionView::Template::Error
provided by Rails 6. This should solve the incorrect backtrace in that case.Here's how this came to be:
ActionView::Template::Error
to display its#original_exception
instead of the top-level error.original_exception
regardless of the exception class. I'm not sure why this was done, but likely it's because there are errors similar toActionView::Template::Error
that it's desirable for.Exception#cause
which provides a standard pattern for the thing that Rails was doing with#original_exception
.#cause
just like it had for errors that had an#original_exception
.#cause
now, where before it would follow#original_exception
only when Rails provided one, and Ruby exceptions frequently have a#cause
but the top-level error is the informative one.Exception#cause
completely, but leave the older Rails#original_exception
behavior in place.#original_exception
and 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::Error
instance 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::Error
as 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_exception
is still there.Fixes #466. Fixes #470.