-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Display nested exceptions on the debug view #32410
Conversation
(@rails-bot has picked a reviewer for you, use r? to override) |
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 do like the idea of this. But how common are exception causes in development?
end | ||
|
||
def source_to_show_id | ||
(traces[trace_to_show].first || {})[:id] |
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.
Hash(traces[trace_to_show].first)[:id]
?
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.
Possible, but I couldn't come up with strong advantages over (... || {})
(very basic syntax that beginners can understand while Hash(...)
is a method call that could be overridden)
<div id="<%= cause.object_id %>" style="display: none;"> | ||
<% wrapper = ActionDispatch::ExceptionWrapper.new(@request.get_header("action_dispatch.backtrace_cleaner"), cause) %> | ||
<%= render "rescues/source", source_extracts: wrapper.source_extracts, show_source_idx: wrapper.source_to_show_id, error_index: index %> | ||
<%= render "rescues/trace", traces: wrapper.traces, trace_to_show: wrapper.trace_to_show, error_index: index %> |
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.
Why don't we just pass in a wrapper here and in this template? I'm not liking the wrapper instantiation in here.
Perhaps then we could do
@wrapper.wrapped_causes.each do |cause_wrapper|
# …
end
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 thought about this too. The Enumerable
would also remove the need of manually tracking the index. I'll implement this if we can get agreement with more folks.
</div> | ||
<% index += 1 %> | ||
<% end %> | ||
|
||
<%= render template: "rescues/_request_and_response" %> |
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.
Lets fix up this render to match the style of the others, while we're 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.
I'd rather send a separate PR to not make the diff unnecessarily larger. Consistency doesn't seem critical in this particular case.
<%= render template: "rescues/_source" %> | ||
<%= render template: "rescues/_trace" %> | ||
<%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx, error_index: 0 %> | ||
<%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show, error_index: 0 %> | ||
<%= render template: "rescues/_request_and_response" %> |
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.
Ditto.
<%= render template: "rescues/_source" %> | ||
<%= render template: "rescues/_trace" %> | ||
<%= render "rescues/source", source_extracts: @source_extracts, show_source_idx: @show_source_idx, error_index: 0 %> | ||
<%= render "rescues/trace", traces: @traces, trace_to_show: @trace_to_show, error_index: 0 %> | ||
<%= render template: "rescues/_request_and_response" %> |
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.
Ditto.
@@ -1,52 +1,54 @@ | |||
<% names = @traces.keys %> | |||
<% names = traces.keys %> |
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.
With this we could spare the multiple instances for error_index: 0
in the render calls.
<% error_index = local_assigns.fetch(:error_index, 0) %>
Any exception that originates from a |
2f84af7
to
b7af040
Compare
slightly updated the PR. |
end | ||
|
||
causes | ||
end |
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 was wondering if there's a better way to convert a linked list to an Enumerable
. Open to suggestions.
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 was trying to fiddle around with Enumerator but couldn't really come up with something.
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.
Maybe? (untested)
def causes_for(exception)
return enum_for(__method__, exception) unless block_given?
yield exception while exception = exception.cause
end
def wrapped_causes_for(exception, backtrace_cleaner)
causes_for(exception).map { |cause| self.class.new(backtrace_cleaner, cause) }
end
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.
@matthewd tried it in my console, it works!
@yuki24 you may also wanna look into making a change in rails/web-console as it relies on the structure of the error page. |
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 think this is pretty much good to go. @yuki24 can you check what this would mean for web-console?
end | ||
|
||
causes | ||
end |
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 was trying to fiddle around with Enumerator but couldn't really come up with something.
@kaspth I haven't looked into it yet will do so if I could find time this weekend. |
e9a84f7
to
fb6f6dd
Compare
@gsamokovarov @kaspth here is a proof-of-concept branch: rails/web-console@master...yuki24:support-for-nested-exceptions The current |
@yuki24 that branch looks doable to me 😊 — for this PR have you tried @matthewd's wrapped causes suggestion yet? 😉 @gsamokovarov how does that seem to you? I'd like to move forward with this in the meantime 😊 |
@kaspth, please do. @yuki24 I have a few comments about the code structure, but feel free to open the PR and we'll work it out on the rails/web-console side. |
@kaspth yes, I like @matthewd's idea. I'll update the PR to use it. @gsamokovarov I'll send a PR shortly. |
fb6f6dd
to
1f525b4
Compare
|
||
def wrapped_causes_for(exception, backtrace_cleaner) | ||
causes_for(exception).map { |cause| self.class.new(backtrace_cleaner, cause) } | ||
end |
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.
Man, this looks clean now 😍
Well done, thanks! 👏 |
This PR adds the ability to show nested exceptions, which I proposed a few weeks ago on the core mailing list.
It's probably easier to understand when you actually see it in action rather than explaining the entire thing, so here comes a screenshot:
I'm going to add the same functionality to the plain text response once this is merged.