Exception: ActionView::Template::Error
- Inherits:
-
ActionViewError
- Object
- StandardError
- ActionViewError
- ActionView::Template::Error
- Defined in:
- lib/action_view/template/error.rb
Overview
The Template::Error exception is raised when the compilation or rendering of the template fails. This exception then gathers a bunch of intimate details and uses it to report a precise exception message.
Constant Summary collapse
- SOURCE_CODE_RADIUS =
:nodoc:
3
Instance Attribute Summary collapse
-
#cause ⇒ Object
readonly
Override to prevent #cause resetting during re-raise.
Instance Method Summary collapse
- #annoted_source_code ⇒ Object
- #file_name ⇒ Object
-
#initialize(template, original_exception = nil) ⇒ Error
constructor
A new instance of Error.
- #line_number ⇒ Object
- #original_exception ⇒ Object
- #source_extract(indentation = 0, output = :console) ⇒ Object
- #sub_template_message ⇒ Object
- #sub_template_of(template_path) ⇒ Object
Constructor Details
#initialize(template, original_exception = nil) ⇒ Error
Returns a new instance of Error.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/action_view/template/error.rb', line 65 def initialize(template, original_exception = nil) if original_exception ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \ "Exceptions will automatically capture the original exception.", caller) end super($!.) set_backtrace($!.backtrace) @cause = $! @template, @sub_templates = template, nil end |
Instance Attribute Details
#cause ⇒ Object (readonly)
Override to prevent #cause resetting during re-raise.
63 64 65 |
# File 'lib/action_view/template/error.rb', line 63 def cause @cause end |
Instance Method Details
#annoted_source_code ⇒ Object
123 124 125 |
# File 'lib/action_view/template/error.rb', line 123 def annoted_source_code source_extract(4) end |
#file_name ⇒ Object
82 83 84 |
# File 'lib/action_view/template/error.rb', line 82 def file_name @template.identifier end |
#line_number ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/action_view/template/error.rb', line 115 def line_number @line_number ||= if file_name regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/ $1 if =~ regexp || backtrace.find { |line| line =~ regexp } end end |
#original_exception ⇒ Object
77 78 79 80 |
# File 'lib/action_view/template/error.rb', line 77 def original_exception ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller) cause end |
#source_extract(indentation = 0, output = :console) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/action_view/template/error.rb', line 95 def source_extract(indentation = 0, output = :console) return unless num = line_number num = num.to_i source_code = @template.source.split("\n") start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min indent = end_on_line.to_s.size + indentation return unless source_code = source_code[start_on_line..end_on_line] formatted_code_for(source_code, start_on_line, indent, output) end |
#sub_template_message ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/action_view/template/error.rb', line 86 def if @sub_templates "Trace of template inclusion: " + @sub_templates.collect(&:inspect).join(", ") else "" end end |
#sub_template_of(template_path) ⇒ Object
110 111 112 113 |
# File 'lib/action_view/template/error.rb', line 110 def sub_template_of(template_path) @sub_templates ||= [] @sub_templates << template_path end |