Exception: Chef::Mixin::Template::TemplateError
- Defined in:
- lib/chef/mixin/template.rb
Constant Summary collapse
- SOURCE_CONTEXT_WINDOW =
2
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#original_exception ⇒ Object
readonly
Returns the value of attribute original_exception.
Instance Method Summary collapse
-
#initialize(original_exception, template, context) ⇒ TemplateError
constructor
A new instance of TemplateError.
- #line_number ⇒ Object
- #message ⇒ Object
- #source_listing ⇒ Object
- #source_location ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(original_exception, template, context) ⇒ TemplateError
Returns a new instance of TemplateError.
56 57 58 |
# File 'lib/chef/mixin/template.rb', line 56 def initialize(original_exception, template, context) @original_exception, @template, @context = original_exception, template, context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
53 54 55 |
# File 'lib/chef/mixin/template.rb', line 53 def context @context end |
#original_exception ⇒ Object (readonly)
Returns the value of attribute original_exception.
53 54 55 |
# File 'lib/chef/mixin/template.rb', line 53 def original_exception @original_exception end |
Instance Method Details
#line_number ⇒ Object
64 65 66 |
# File 'lib/chef/mixin/template.rb', line 64 def line_number @line_number ||= $1.to_i if original_exception.backtrace.find {|line| line =~ /\(erubis\):(\d+)/ } end |
#message ⇒ Object
60 61 62 |
# File 'lib/chef/mixin/template.rb', line 60 def @original_exception. end |
#source_listing ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/chef/mixin/template.rb', line 72 def source_listing @source_listing ||= begin line_index = line_number - 1 beginning_line = line_index <= SOURCE_CONTEXT_WINDOW ? 0 : line_index - SOURCE_CONTEXT_WINDOW source_size = SOURCE_CONTEXT_WINDOW * 2 + 1 lines = @template.split(/\n/) contextual_lines = lines[beginning_line, source_size] output = [] contextual_lines.each_with_index do |line, index| line_number = (index+beginning_line+1).to_s.rjust(3) output << "#{line_number}: #{line}" end output.join("\n") end end |
#source_location ⇒ Object
68 69 70 |
# File 'lib/chef/mixin/template.rb', line 68 def source_location "on line ##{line_number}" end |
#to_s ⇒ Object
88 89 90 91 |
# File 'lib/chef/mixin/template.rb', line 88 def to_s "\n\n#{self.class} (#{}) #{source_location}:\n\n" + "#{source_listing}\n\n #{original_exception.backtrace.join("\n ")}\n\n" end |