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 error reporter doesn't report exceptions in production #51002
Comments
This change to the module ActionDispatch
class Executor
def initialize(app, executor)
@app, @executor = app, executor
end
def call(env)
state = @executor.run!(reset: true)
begin
response = @app.call(env)
returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
if (exception = env['action_dispatch.exception'])
@executor.error_reporter.report(exception, handled: false, source: "application.action_dispatch")
end
returned
rescue => error
@executor.error_reporter.report(error, handled: false, source: "application.action_dispatch")
raise
ensure
state.complete! unless returned
end
end
end
end |
I stumbled across this issue by publishing the To my mind, this feels like a bug. A default Rails application should report exceptions to the error reporter, especially in the production context, even if the error is swallowed and converted into an valid HTTP response. |
I have dug in more, and I have a clearer picture of what is going on. The top-level point is that it is mostly a happy coincidence that errors are reported in development. But, let me explain. Errors are reported via the rails/actionpack/lib/action_dispatch/middleware/executor.rb Lines 11 to 21 in 3b8222c
You will notice that only raised errors are reported, as we are inside of a rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb Lines 30 to 41 in 3b8222c
Inside of this middleware, inside of a rails/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb Lines 177 to 191 in 3b8222c
You can inspect the So, the question becomes, how are errors reported in In a standard, default Rails application, you will find the following middleware stack in
In comparison, you will see this middleware stack in
Diffing these two arrays (
One of these middlewares allows errors to be reported. When adding additional logging to the middlewares, it became clear that errors were reported in rails/actionpack/lib/action_dispatch/middleware/reloader.rb Lines 3 to 14 in 3b8222c
It inherits from the Important Errors that occur within the HTTP request->response lifecycle are only reported in |
I have a simple repo ready for experimentation and exploration here: https://github.com/fractaledmind/rails-error-reporter-demo |
cc @casperisfine for Monday. |
Fix: rails#51002 In the default middleware stack, the `ShowExceptions` middleware is lower than `ActionDispatch::Execturor` and will handle most exceptions causing `Executor` not to witness any. Instead we need to rely on `action_dispatch.exception` being added into the request env.
Fix: rails#51002 In the default middleware stack, the `ShowExceptions` middleware is lower than `ActionDispatch::Execturor` and will handle most exceptions causing `Executor` not to witness any. Instead we need to rely on `action_dispatch.exception` being added into the request env.
Fix: rails#51002 In the default middleware stack, the `ShowExceptions` middleware is lower than `ActionDispatch::Execturor` and will handle most exceptions causing `Executor` not to witness any. Instead we need to rely on `action_dispatch.exception` being added into the request env.
Fix: rails#51002 In the default middleware stack, the `ShowExceptions` middleware is lower than `ActionDispatch::Execturor` and will handle most exceptions causing `Executor` not to witness any. Instead we need to rely on `action_dispatch.exception` being added into the request env.
Fix: rails#51002 In the default middleware stack, the `ShowExceptions` middleware is lower than `ActionDispatch::Execturor` and will handle most exceptions causing `Executor` not to witness any. Instead we need to rely on `action_dispatch.exception` being added into the request env.
Fix: rails#51002 In the default middleware stack, the `ShowExceptions` middleware is lower than `ActionDispatch::Execturor` and will handle most exceptions causing `Executor` not to witness any. Instead we need to rely on `action_dispatch.exception` being added into the request env.
Fix: rails#51002 In the default middleware stack, the `ShowExceptions` middleware is lower than `ActionDispatch::Execturor` and will handle most exceptions causing `Executor` not to witness any. Instead we need to rely on `action_dispatch.exception` being added into the request env.
In production, an exception that occurs in the HTTP request lifecycle is rendered and not raised. The
Executor
middleware reports only raised exceptions. This severely neuters, IMHO, the value of the new error reporter.Expected behavior
Exceptions that occur within the HTTP request lifecycle in production, while still being rendered, are also reported to the error reporter.
Actual behavior
Exceptions that occur within the HTTP request lifecycle in production are not reported to the error reporter.
System configuration
Rails version: >7.0
The text was updated successfully, but these errors were encountered: