Partial incompatibility with rails 7.1
I realised after upgrading to rails 7.1 that when I encounter an exception in the view, I do not get the familiar ActionDispatch::DebugExceptions page anymore, but rather my exceptions_app
After much digging, I realised there is a crash inside ActionDispatch::DebugExceptions when trying to display the backtrace, thus making the middleware not render the page, and the exception ends up getting caught by ActionDispatch::ShowExceptions down the road.
Here's the exception and the stacktrace :
eval error: undefined method `last' for nil:NilClass
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionview-7.1.1/lib/action_view/template/handlers/erb.rb:142:in `find_offset'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionview-7.1.1/lib/action_view/template/handlers/erb.rb:46:in `translate_location'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionview-7.1.1/lib/action_view/template.rb:229:in `translate_location'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/exception_wrapper.rb:258:in `spot'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/exception_wrapper.rb:302:in `extract_source'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/exception_wrapper.rb:206:in `block in source_extracts'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/exception_wrapper.rb:205:in `map'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/exception_wrapper.rb:205:in `source_extracts'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:126:in `create_template'
/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:78:in `render_for_browser_request'
(rdbg)/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:1:in `rescue in call'
better_html sounded like a good suspect, removing it from the bundle fixes the issue.
Alternatively, disabling runtime checks fixes the issue too :
BetterHtml.configure do |config|
config.template_exclusion_filter = proc { true }
end
So it seems that the custom parser conflicts with the way rails 7.1 tries to extract the source.
I also had a lot of bad experiences with the latest Rails version 7.2.2 and better html. No error page was displayed correctly anymore. Ended up in removing the gem completely.
I submitted rails/rails#53657 that should resolve this problem.