-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Introduce ActionDispatch::DebugExceptions interceptors #23868
Introduce ActionDispatch::DebugExceptions interceptors #23868
Conversation
r? @matthewd (@rails-bot has picked a reviewer for you, use r? to override) |
97c9795
to
bf198fe
Compare
backtrace_cleaner = request.get_header('action_dispatch.backtrace_cleaner') | ||
wrapper = ExceptionWrapper.new(backtrace_cleaner, exception) | ||
|
||
@interceptors.each do |interceptor| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get rid of the transitory @interceptors
, and just call self.class.interceptors
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injected it, so I can test it more easily – no need to keep track of the global state during the test run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷 I just think it would make sense to use the direct variable we will iterating on, instead of creating a shadow variable, that we won't even be changing.
As the maintainer of an exception notifier ( |
bf198fe
to
fe88654
Compare
raise exception unless request.show_exceptions? | ||
render_exception(request, exception) | ||
render_exception(request, exception, wrapper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this breaks the render_exception interface, and plugin authors already depend on it. I'm going with the duplicated code approach. Yeah, I like DRY code, but sometimes the duplication is so much better than breaking interfaces or leaking abstractions.
b6d25e4
to
24423aa
Compare
@gsamokovarov Is @rafaelfranca @matthewd Is there anything I can do to help move this forward? |
@tgxworld Yes, it is still monkey patching... You can make I still stand by the interceptors, though. They are super simple and provide what most of the plugins monkey patching |
The idea looks good to me. @gsamokovarov can you rebase it? |
95fd046
to
7c0d767
Compare
Plugins interacting with the exceptions caught and displayed by ActionDispatch::DebugExceptions currently have to monkey patch it to get the much needed exception for their calculation. With DebugExceptions.register_interceptor, plugin authors can hook into DebugExceptions and process the exception, before being rendered. They can store it into the request and process it on the way back of the middleware chain execution or act on it straight in the interceptor. The interceptors can be play blocks, procs, lambdas or any object that responds to `#call`.
7c0d767
to
d25fba8
Compare
@rafaelfranca I have rebased it. 👌 |
😍 Thank you @gsamokovarov and @rafaelfranca |
Plugins interacting with the exceptions caught and displayed by
ActionDispatch::DebugExceptions
currently have to monkey patch it to getthe much needed exception for their calculation.
With
DebugExceptions.register_interceptor
, plugin authors can hook intoDebugExceptions
and process the exception, before being rendered. Theycan store it into the request and process it on the way back of the
middleware chain execution or act on it straight in the interceptor.
The interceptors can be plain blocks, procs, lambdas or any object that
responds to
#call
.You can see
web-console
implemented through the interceptor API here.Other plugin authors can benefit from this API as well. Most of the error
reporting plugins can use this.