Permalink
Browse files

Added TemplateError#backtrace that makes it much easier to debug temp…

…late errors from unit and functional tests

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@145 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2c5a2e7 commit aaf6956c4776d6c43f77ab540cb51becdac3e00e @dhh dhh committed Dec 13, 2004
Showing with 12 additions and 3 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +10 −3 actionpack/lib/action_view/template_error.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Added TemplateError#backtrace that makes it much easier to debug template errors from unit and functional tests
+
* Added display of error messages with scaffolded form pages
* Added option to ERB templates to swallow newlines by using <% if something -%> instead of just <% if something %>. Example:
@@ -28,7 +28,7 @@ def sub_template_message
end
end
- def source_extract
+ def source_extract(indention = 0)
source_code = IO.readlines(@file_name)
start_on_line = [ line_number - SOURCE_CODE_RADIUS - 1, 0 ].max
@@ -37,9 +37,9 @@ def source_extract
line_counter = start_on_line
extract = source_code[start_on_line..end_on_line].collect do |line|
line_counter += 1
- "#{line_counter}: " + line
+ "#{' ' * indention}#{line_counter}: " + line
end
-
+
extract.join
end
@@ -71,6 +71,13 @@ def to_s
"\n\n"
end
+ def backtrace
+ [
+ "On line ##{line_number} of #{file_name}\n\n#{source_extract(4)}\n " +
+ clean_backtrace(original_exception).join("\n ")
+ ]
+ end
+
private
def strip_base_path(file_name)
file_name.gsub(@base_path, "")

0 comments on commit aaf6956

Please sign in to comment.