diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-10-26 22:04:43 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-10-26 22:04:43 -0500 |
commit | d27efbfbf5e4426ad50d4479bab08fa4ae051360 (patch) | |
tree | 98851f86fa0e91409faf8ce9eb60c41a1b5860b6 /actionpack/lib | |
parent | bf17c8a531bc8059d50ad731398002a3e7162a7d (diff) | |
parent | dbcbbcf2bc58e8971672b143d1c52c0244e33f26 (diff) | |
download | rails-d27efbfbf5e4426ad50d4479bab08fa4ae051360.tar.gz rails-d27efbfbf5e4426ad50d4479bab08fa4ae051360.tar.bz2 rails-d27efbfbf5e4426ad50d4479bab08fa4ae051360.zip |
Merge pull request #17362 from bronzle/fix_debug_exceptions_app
Show the user’s application in the source window and select the correct ...
Diffstat (limited to 'actionpack/lib')
3 files changed, 35 insertions, 25 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 274f6f2f22..ff72592b94 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -35,10 +35,23 @@ module ActionDispatch if env['action_dispatch.show_detailed_exceptions'] request = Request.new(env) + traces = traces_from_wrapper(wrapper) + + trace_to_show = 'Application Trace' + if traces[trace_to_show].empty? + trace_to_show = 'Full Trace' + end + + if source_to_show = traces[trace_to_show].first + source_to_show_id = source_to_show[:id] + end + template = ActionView::Base.new([RESCUES_TEMPLATE_PATH], request: request, exception: wrapper.exception, - traces: traces_from_wrapper(wrapper), + traces: traces, + show_source_idx: source_to_show_id, + trace_to_show: trace_to_show, routes_inspector: routes_inspector(exception), source_extract: wrapper.source_extract, line_number: wrapper.line_number, @@ -97,31 +110,28 @@ module ActionDispatch # Augment the exception traces by providing ids for all unique stack frame def traces_from_wrapper(wrapper) application_trace = wrapper.application_trace - framework_trace = wrapper.framework_trace - full_trace = wrapper.full_trace - - if application_trace && framework_trace - id_counter = 0 - - application_trace = application_trace.map do |trace| - prev = id_counter - id_counter += 1 - { id: prev, trace: trace } - end - - framework_trace = framework_trace.map do |trace| - prev = id_counter - id_counter += 1 - { id: prev, trace: trace } + framework_trace = wrapper.framework_trace + full_trace = wrapper.full_trace + + appplication_trace_with_ids = [] + framework_trace_with_ids = [] + full_trace_with_ids = [] + + if full_trace + full_trace.each_with_index do |trace, idx| + id_trace = { + id: idx, + trace: trace + } + appplication_trace_with_ids << id_trace if application_trace.include? trace + framework_trace_with_ids << id_trace if framework_trace.include? trace + full_trace_with_ids << id_trace end - - full_trace = application_trace + framework_trace end - { - "Application Trace" => application_trace, - "Framework Trace" => framework_trace, - "Full Trace" => full_trace + "Application Trace" => appplication_trace_with_ids, + "Framework Trace" => framework_trace_with_ids, + "Full Trace" => full_trace_with_ids } end end diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb index ba29e26930..eabac3a9d2 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb @@ -1,7 +1,7 @@ <% if @source_extract %> <% @source_extract.each_with_index do |extract_source, index| %> <% if extract_source[:code] %> - <div class="source <%="hidden" if index != 0%>" id="frame-source-<%=index%>"> + <div class="source <%="hidden" if @show_source_idx != index%>" id="frame-source-<%=index%>"> <div class="info"> Extracted source (around line <strong>#<%= extract_source[:line_number] %></strong>): </div> diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb index f62caf51d7..ab57b11c7d 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb @@ -12,7 +12,7 @@ <% end %> <% @traces.each do |name, trace| %> - <div id="<%= name.gsub(/\s/, '-') %>" style="display: <%= (name == "Application Trace") ? 'block' : 'none' %>;"> + <div id="<%= name.gsub(/\s/, '-') %>" style="display: <%= (name == @trace_to_show) ? 'block' : 'none' %>;"> <pre><code><% trace.each do |frame| %><a class="trace-frames" data-frame-id="<%= frame[:id] %>" href="#"><%= frame[:trace] %></a><br><% end %></code></pre> </div> <% end %> |