Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip calling concat() when exception.annotated_source_code returns ni… #38820

Closed
wants to merge 1 commit into from

Conversation

AnomalousBit
Copy link

Summary

This fix is to address an identical problem described in #36719.

I can confirm the more general issue of some exceptions not being logged in the console on development still exists. I've had a couple of issues crop up in the past weeks around sassc compilation errors and today with an ActionView::Template::Error (Multiple files with the same output path cannot be linked) error, with the exceptions never being displayed in the console, leaving me completely stumped as to why my Rails app was returning HTTP 500 / error pages.

In my situation, I was able to step down to https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L146 and determine that concat() is throwing a new exception, causing the logging to be completely silenced when exception.annotated_source_code returns nil.

I've self-tested this fix and it now logs the exceptions as one would expect. Hopefully this saves people a lot of time that I've spent tracking down silent errors.

Other Information

I was able to trigger this silent exception issue when a ActionView::Template::Error (Multiple files with the same output path cannot be linked...) exception was thrown. The easiest way I know to do this is make a copy of an existing coffeescript file with another preprocessor extension such as having both files exist: /app/assets/javascripts/file.coffee and /app/assets/javascripts/file.coffee.erb then try loading a page in your browser.

@rails-bot rails-bot bot added the actionpack label Mar 25, 2020
@eugeneius
Copy link
Member

It doesn't seem possible for annotated_source_code to return nil since #36532. That fix hasn't been released yet, but it's backported and will be part of 6.0.3.

If you point your Gemfile to the 6-0-stable branch, like this:

gem "rails", git: "https://github.com/rails/rails", branch: "6-0-stable"

Can you still reproduce the error without this change?

@AnomalousBit
Copy link
Author

Testing the couple of silent exceptions I've come across recently, the stable branch does fix the issue with annotated_source_code returning nil.

The discussion behind #36532 centers around the changes being defensive, wouldn't this minor change just be another defensive check for the concat() call? No worries about whether merging or not, just thought it might still make sense given the context.

Thanks for taking notice and sharing @eugeneius .

@eugeneius
Copy link
Member

I don't think we need an extra level of defence here: if the "silent exceptions" issue resurfaces, it's more likely to be due to an error in a different area of the code that causes the same problem.

@olivierphi
Copy link

Just spent a few hours on a bug caused by this same issue, before I find this thread...
With the version v6.0.2.2 of the actionpack gem I was getting a mysterious "error 500" page (the default one for the "production" environment) even though I was in "development" mode.
The log file was not displaying any relevant information either (only a vague "Completed 500 Internal Server Error" message after the ERB rendering message).

Commenting this line (message.concat(exception.annotated_source_code) if exception.respond_to?(:annotated_source_code)) makes it work again, and shows that it was a Sprockets::FileNotFound error that was causing the bug (because the file was renamed) ; and it seems that this line was preventing the proper report in "development" mode somehow - or was not defensive enough to handle unexpected results coming up for .the exception.annotated_source_code call (which is indeed returning nil in this case).

Maybe the extra level of defence here could be useful, as it's really hard to debug when there is absolutelynothing showing up in the HTML page nor the logs even in the "development" environment? 🙂

@kaspth
Copy link
Contributor

kaspth commented Apr 15, 2020

@drbenton did you check this? #38820 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants