diff --git a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb index d1cadbd082..ee69c8b49d 100644 --- a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb +++ b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb @@ -57,7 +57,7 @@ module ActionDispatch end def source_extract - if trace = application_trace.first + if application_trace && trace = application_trace.first file, line, _ = trace.split(":") @file = file @line_number = line.to_i @@ -92,6 +92,7 @@ module ActionDispatch end def source_fragment(path, line) + return unless Rails.respond_to?(:root) && Rails.root full_path = Rails.root.join(path) if File.exists?(full_path) File.open(full_path, "r") do |file| diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb index a1b377f68c..01faf5a475 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb @@ -1,17 +1,44 @@ -
- Showing <%=h @exception.file_name %> where line #<%=h @exception.line_number %> raised: -
<%=h @exception.message %>
-
++ Showing <%=h @exception.file_name %> where line #<%=h @exception.line_number %> raised: +
<%=h @exception.message %>
+
-Extracted source (around line #<%=h @exception.line_number %>): -
<%=h @exception.source_extract %>
+ Extracted source (around line #<%=h @exception.line_number %>): +
+
+ <% @source_extract.keys.each do |line_number| %>
+<%= line_number -%>
+ <% end %>
+
+ |
+
++<% @source_extract.each do |line, source| -%>+ |
+
<%=h @exception.sub_template_message %>
+<%=h @exception.sub_template_message %>
-<%= render template: "rescues/_trace" %> -<%= render template: "rescues/_request_and_response" %> + <%= render template: "rescues/_trace" %> + <%= render template: "rescues/_request_and_response" %> +