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

Log internal ActionDispatch::DebugExceptions errors #29131

Conversation

gsamokovarov
Copy link
Contributor

What happens when your last resort error handling code crashes by
itself? This is a good question. Currently, Rails tries really hard to
at least show something to the browsers and not leave the end users with
a blank page.

For this to happen we have a carefully arranged chain of middlewares
that can:

  • show developer friendly information about an error
  • show a generic fallback (Something went wrong) error response

We do try really hard to make sure those middlewares don't crash,
however sometimes they do. Most of the time, it's not even Rails' fault.
For example the ActionDispatch::DebugExceptions#render_exception, as
private as it is, it's commonly freedom patched by a lot of plugins,
that need to interact with application errors, web-console included.

The API of the render_exception method has changed in the past, and it
can change in the future. This may be a common place of errors during
upgrades.

Previously, when ActionDispatch::DebugExceptions crashes, the default
fallback error response defined in ActionDispatch::ShowExceptions
kicks in. However, the internal error is not logged anywhere and this
may throw a lot of Rails developers into limbo. What is going on? Have
I done something? What's the error?

For someone unfamiliar with the stack, this is quite the mysterious
problem. We have had crashes in web-console and we have tried to tackle
them with solutions like rails/web-console#181. This is a more general
solution that can benefit all the plugins relying on overriding
#render_exception.

Now, when the plugins or ActionDispatch::DebugExceptions itself
crashes, we will try very hard to log the internal error to the logs
itself or the stderr if none of the standard logs have been
initialized when the crash occurred.

@rails-bot
Copy link

r? @matthewd

(@rails-bot has picked a reviewer for you, use r? to override)

@gsamokovarov gsamokovarov force-pushed the log-internal-errors-in-debug-exceptions branch from 7291858 to 7dcc1c7 Compare May 18, 2017 11:51
Copy link
Contributor

@maclover7 maclover7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few small docs comments :)


# If we got to this point, the only thing that can crash is the
# render_exception method. As private as it is, it's monkey patched by a
# lot of plugins, that need to interact with application errors,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️ the comma between plugins and that

@@ -66,7 +66,21 @@ def call(env)
response
rescue Exception => exception
raise exception unless request.show_exceptions?
render_exception(request, exception)

# If we got to this point, the only thing that can crash is the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try and pare this down a little bit, to just the essential? I feel like if people want the whole story, we should look at the commit for context 😬 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think so too, wrote it before the commit. I'll drop it, the PR is descriptive enough.

@gsamokovarov gsamokovarov force-pushed the log-internal-errors-in-debug-exceptions branch from 7dcc1c7 to 4bf5532 Compare May 19, 2017 06:57
What happens when your last resort error handling code crashes by
itself? This is a good question. Currently, Rails tries really hard to
at least show something to the browsers and not leave the end users with
a blank page.

For this to happen we have a carefully arranged chain of middlewares
that can:

- show developer friendly information about an error
- show a generic fallback (`Something went wrong`) error response

We do try really hard to make sure those middlewares don't crash,
however sometimes they do. Most of the time, it's not even Rails' fault.
For example the `ActionDispatch::DebugExceptions#render_exception`, as
private as it is, it's commonly freedom patched by a lot of plugins,
that need to interact with application errors, web-console included.

The API of the render_exception method has changed in the past, and it
can change in the future. This may be a common place of errors during
upgrades.

Previously, when `ActionDispatch::DebugExceptions` crashes, the default
fallback error response defined in `ActionDispatch::ShowExceptions`
kicks in. However, the internal error is not logged anywhere and this
may throw a lot of Rails developers into limbo. What is going on? Have
I done something? What's the error?

For someone unfamiliar with the stack, this is quite the mysterious
problem. We have had crashes in web-console and we have tried to tackle
them with solutions like rails/web-console#181. This is a more general
solution that can benefit all the plugins relying on overriding
`#render_exception`.

Now, when the plugins or `ActionDispatch::DebugExceptions` itself
crashes, we will try very hard to log the internal error to the logs
itself or the `stderr` if none of the standard logs have been
initialized when the crash occurred.
@rails-bot
Copy link

rails-bot bot commented Dec 18, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 18, 2019
@rails-bot rails-bot bot closed this Dec 25, 2019
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.

4 participants