diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-10-15 19:05:15 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-10-15 19:05:15 +0000 |
commit | 3625dfaad5901e7595a3541c8ddfe890fefff0a6 (patch) | |
tree | 0d0b8024834e87f7af10b512f942c687b846efd5 /actionpack/lib/action_view | |
parent | 49ec08aaa76c4d1e5ea3286fa56e4afa927bf135 (diff) | |
download | rails-3625dfaad5901e7595a3541c8ddfe890fefff0a6.tar.gz rails-3625dfaad5901e7595a3541c8ddfe890fefff0a6.tar.bz2 rails-3625dfaad5901e7595a3541c8ddfe890fefff0a6.zip |
Clean up error pages by providing better backtraces
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2624 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/template_error.rb | 33 |
2 files changed, 11 insertions, 24 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index c4fb589063..c65faeafbd 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -405,7 +405,7 @@ module ActionView #:nodoc: 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 diff --git a/actionpack/lib/action_view/template_error.rb b/actionpack/lib/action_view/template_error.rb index 28f11675cf..9f7fc416c9 100644 --- a/actionpack/lib/action_view/template_error.rb +++ b/actionpack/lib/action_view/template_error.rb @@ -9,7 +9,7 @@ module ActionView 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,9 +46,9 @@ module ActionView 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 @@ -56,20 +56,21 @@ module ActionView 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 @@ module ActionView 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) |