From 1ed264bc60f3c76ba7fab339806fa1757702a46b Mon Sep 17 00:00:00 2001 From: Ryan Dao Date: Wed, 30 Jul 2014 15:35:47 +0700 Subject: Retrieve source code for the entire stack trace Provide the ability to extract the source code of the entire exception stack trace, not just the frame raising the error. This improves debugging capability of the error page, especially for framework-related errors. --- .../middleware/templates/rescues/_source.erb | 40 +++++++++++--------- .../middleware/templates/rescues/_trace.html.erb | 44 ++++++++++++++++++---- .../middleware/templates/rescues/_trace.text.erb | 10 +---- .../middleware/templates/rescues/layout.erb | 6 +++ .../templates/rescues/template_error.html.erb | 25 +----------- .../templates/rescues/template_error.text.erb | 1 - 6 files changed, 67 insertions(+), 59 deletions(-) (limited to 'actionpack/lib/action_dispatch/middleware/templates') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb index 38429cb78e..51660a619b 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.erb @@ -1,25 +1,29 @@ <% if @source_extract %> -
-
- Extracted source (around line #<%= @line_number %>): -
-
- - - +
-
-            <% @source_extract.keys.each do |line_number| %>
+  <% @source_extract.each_with_index do |extract_source, index| %>
+    <% if extract_source[:code] %>
+      
" id="frame-source-<%=index%>"> +
+ Extracted source (around line #<%= extract_source[:line_number] %>): +
+
+ + + + <% end %> + + - -
+
+                  <% extract_source[:code].keys.each do |line_number| %>
 <%= line_number -%>
-            <% end %>
-          
-
-<% @source_extract.each do |line, source| -%>
"><%= source -%>
<% end -%> +<% extract_source[:code].each do |line, source| -%>
"><%= source -%>
<% end -%>
-
-
+
+
+
+ <% end %> + <% end %> <% end %> 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 b181909bff..f62caf51d7 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb @@ -1,9 +1,4 @@ -<% - traces = { "Application Trace" => @application_trace, - "Framework Trace" => @framework_trace, - "Full Trace" => @full_trace } - names = traces.keys -%> +<% names = @traces.keys %>

Rails.root: <%= defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : "unset" %>

@@ -16,9 +11,42 @@ <%= name %> <%= '|' unless names.last == name %> <% end %> - <% traces.each do |name, trace| %> + <% @traces.each do |name, trace| %>
;"> -
<%= trace.join "\n" %>
+
<% trace.each do |frame| %><%= frame[:trace] %>
<% end %>
<% end %> + + diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb index d4af5c9b06..36b01bf952 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb @@ -1,15 +1,9 @@ -<% - traces = { "Application Trace" => @application_trace, - "Framework Trace" => @framework_trace, - "Full Trace" => @full_trace } -%> - Rails.root: <%= defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : "unset" %> -<% traces.each do |name, trace| %> +<% @traces.each do |name, trace| %> <% if trace.any? %> <%= name %> -<%= trace.join("\n") %> +<%= trace.map(&:trace).join("\n") %> <% end %> <% end %> diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb index bc5d03dc10..e0509f56f4 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb @@ -116,9 +116,15 @@ background-color: #FFCCCC; } + .hidden { + display: none; + } + a { color: #980905; } a:visited { color: #666; } + a.trace-frames { color: #666; } a:hover { color: #C52F24; } + a.trace-frames.selected { color: #C52F24 } <%= yield :style %> diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb index 027a0f5b3e..c1e8b6cae3 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb @@ -1,4 +1,3 @@ -<% @source_extract = @exception.source_extract(0, :html) %>

<%= @exception.original_exception.class.to_s %> in @@ -12,29 +11,7 @@

<%= h @exception.message %>
-
-
-

Extracted source (around line #<%= @exception.line_number %>):

-
-
- - - - - -
-
-            <% @source_extract.keys.each do |line_number| %>
-<%= line_number -%>
-            <% end %>
-          
-
-
-<% @source_extract.each do |line, source| -%>
"><%= source -%>
<% end -%> -
-
-
-
+ <%= render template: "rescues/_source" %>

<%= @exception.sub_template_message %>

diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb index 5da21d9784..77bcd26726 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb @@ -1,4 +1,3 @@ -<% @source_extract = @exception.source_extract(0, :html) %> <%= @exception.original_exception.class.to_s %> in <%= @request.parameters["controller"].camelize if @request.parameters["controller"] %>#<%= @request.parameters["action"] %> Showing <%= @exception.file_name %> where line #<%= @exception.line_number %> raised: -- cgit v1.2.3