Permalink
Browse files

Clean up error pages by providing better backtraces

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2624 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 49ec08a commit 3625dfaad5901e7595a3541c8ddfe890fefff0a6 @seckar seckar committed Oct 15, 2005
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Clean up error pages by providing better backtraces [Nicholas Seckar]
+
* Raise an exception if an attempt is made to insert more session data into the ActiveRecordStore data column than the column can hold. #2234. [justin@textdrive.com]
* Removed references to assertions.rb from actionpack assert's backtraces. Makes error reports in functional unit tests much less noisy. [Tobias Luetke]
View
15 actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml
@@ -1,20 +1,9 @@
-<%
- clean_backtrace = @exception.backtrace.collect { |line| Object.const_defined?(:RAILS_ROOT) ? line.gsub(RAILS_ROOT, "") : line }
- app_trace = clean_backtrace.reject { |line| line =~ /(vendor|dispatch|ruby)/ }
- framework_trace = clean_backtrace - app_trace
-%>
-
<h1>
<%=h @exception.class.to_s %> in
<%=h (@request.parameters["controller"] || "<controller not set>").capitalize %>#<%=h @request.parameters["action"] || "<action not set>" %>
</h1>
-<pre><%=h Object.const_defined?(:RAILS_ROOT) ? @exception.message.gsub(RAILS_ROOT, "") : @exception.message %></pre>
-
-<% unless app_trace.empty? %><pre><code><%=h app_trace.join("\n") %></code></pre><% end %>
+<pre><%=h @exception.clean_message %></pre>
-<% unless framework_trace.empty? %>
- <a href="#" onclick="document.getElementById('framework_trace').style.display='block'; return false;">Show framework trace</a>
- <pre id="framework_trace" style="display:none"><code><%=h framework_trace.join("\n") %></code></pre>
-<% end %>
+<%= render_file(@rescues_path + "/_trace.rhtml", false) %>
<%= render_file(@rescues_path + "/_request_and_response.rhtml", false) %>
View
6 actionpack/lib/action_controller/templates/rescues/template_error.rhtml
@@ -13,7 +13,9 @@
<p><%=h @exception.sub_template_message %></p>
-<a href="#" onclick="document.getElementById('framework_trace').style.display='block'">Show template trace</a>
-<pre id="framework_trace" style="display:none"><code><%=h @exception.original_exception.backtrace.collect { |line| Object.const_defined?(:RAILS_ROOT) ? line.gsub(RAILS_ROOT, "") : line }.join("\n") %></code></pre>
+<% @real_exception = @exception
+ @exception = @exception.original_exception || @exception %>
+<%= render_file(@rescues_path + "/_trace.rhtml", false) %>
+<% @exception = @real_exception %>
<%= render_file(@rescues_path + "/_request_and_response.rhtml", false) %>
View
2 actionpack/lib/action_view/base.rb
@@ -405,7 +405,7 @@ def compile_template(extension, template, file_name, local_assigns)
begin
unless file_name.blank?
- CompiledTemplates.module_eval(render_source, File.expand_path(file_name), -line_offset)
+ CompiledTemplates.module_eval(render_source, file_name, -line_offset)
else
CompiledTemplates.module_eval(render_source, 'compiled-template', -line_offset)
end
View
33 actionpack/lib/action_view/template_error.rb
@@ -9,7 +9,7 @@ class TemplateError < ActionViewError #:nodoc:
def initialize(base_path, file_name, assigns, source, original_exception)
@base_path, @assigns, @source, @original_exception =
base_path, assigns, source, original_exception
- @file_name = File.expand_path file_name
+ @file_name = file_name
end
def message
@@ -46,30 +46,31 @@ def sub_template_of(file_name)
end
def line_number
- if @file_name
- regexp = /#{Regexp.escape @file_name}(?:\(.*?\))?:(\d+)/ # A regexp to match a line number in our file
- [@original_exception.message, @original_exception.backtrace].flatten.each do |line|
+ if file_name
+ regexp = /#{Regexp.escape file_name}:(\d+)\s*$/
+ [@original_exception.message, @original_exception.clean_backtrace].flatten.each do |line|
return $1.to_i if regexp =~ line
end
end
0
end
def file_name
- strip_base_path(@file_name)
+ stripped = strip_base_path(@file_name)
+ stripped[0] == ?/ ? stripped[1..-1] : stripped
end
def to_s
"\n\n#{self.class} (#{message}) on line ##{line_number} of #{file_name}:\n" +
source_extract + "\n " +
- clean_backtrace(original_exception).join("\n ") +
+ original_exception.clean_backtrace.join("\n ") +
"\n\n"
end
def backtrace
[
"On line ##{line_number} of #{file_name}\n\n#{source_extract(4)}\n " +
- clean_backtrace(original_exception).join("\n ")
+ original_exception.clean_backtrace.join("\n ")
]
end
@@ -78,21 +79,7 @@ def strip_base_path(file_name)
file_name = File.expand_path(file_name).gsub(/^#{Regexp.escape File.expand_path(RAILS_ROOT)}/, '')
file_name.gsub(@base_path, "")
end
-
- if defined?(RAILS_ROOT)
- RailsRootRegexp = %r((#{Regexp.escape RAILS_ROOT}|#{Regexp.escape File.expand_path(RAILS_ROOT)})/(.*)?)
- else
- RailsRootRegexp = /^()(.*)$/
- end
-
- def clean_backtrace(exception)
- exception.backtrace.collect do |line|
- line.gsub %r{^(\s*)(/[-\w\d\./]+)} do
- leading, path = $1, $2
- path = $2 if RailsRootRegexp =~ path
- leading + path
- end
- end
- end
end
end
+
+Exception::TraceSubstitutions << [/:in\s+`_run_(html|xml).*'\s*$/, ''] if defined?(Exception::TraceSubstitutions)

0 comments on commit 3625dfa

Please sign in to comment.