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

Rails Logger not receiving exception with AJAX requests #429

Open
Benjamin-Dobell opened this issue Oct 29, 2018 · 1 comment
Open

Rails Logger not receiving exception with AJAX requests #429

Benjamin-Dobell opened this issue Oct 29, 2018 · 1 comment
Labels

Comments

@Benjamin-Dobell
Copy link

Benjamin-Dobell commented Oct 29, 2018

I've seen other users mention that they're still running into issues with Ruby 2.5.x and Rails 5, and I'm in the same boat. However, the issue is that I'm not seeing logged errors.

better_errors (2.5.0) and binding_of_caller (0.8.0) are both fully updated so I started debugging the issue and found the issue to be a result of StackFrame injecting gem names into the backtrace, which is then silenced by Rail's default BacktraceCleaner setup.

Specifically:

https://github.com/BetterErrors/better_errors/blob/master/lib/better_errors/stack_frame.rb#L39

is silenced by:

https://github.com/rails/rails/blob/master/railties/lib/rails/backtrace_cleaner.rb#L7 and https://github.com/rails/rails/blob/master/railties/lib/rails/backtrace_cleaner.rb#L19

What's got me a little stumped is that the relevant functionality has been part of both BetterErrors and Rails for a very long time.

This is an issue with AJAX requests that fail. The BetterErrors prompt isn't shown because the HTML isn't displayed (no page reload, because AJAX). So I'm expecting that I can at least see the backtrace in the log. However, at present that's not happening.

@RobinDaugherty
Copy link
Member

RobinDaugherty commented Oct 31, 2018

I'll look into why the log is not getting the exception, it should.

When Better Errors handles an exception, it returns a 500 status code to the current request. Make sure your Javascript code that performs the ajax request is handling a failure. You should generally give the user some feedback in that case, and you can also show the error details in the console.

When developing, look at the server response in your browser developer tools. For example, the Network tab in Chrome. Better Errors sends a text response containing the backtrace in a human-readable format, which will cause a problem for the AJAX callback if that parses the response as JSON without looking to see if the response Content-Type is actually JSON.

@RobinDaugherty RobinDaugherty changed the title Logging Errors with AJAX requests Rails Logger not receiving exception with AJAX requests Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants