# class Chef::Mixin::Template::TemplateError

### Constants

SOURCE_CONTEXT_WINDOW

### Attributes

context[R]
original_exception[R]

### Public Class Methods

new(original_exception, template, context) click to toggle source

    # File lib/chef/mixin/template.rb, line 183
    def initialize(original_exception, template, context)
      @original_exception, @template, @context = original_exception, template, context
    end

### Public Instance Methods

line_number() click to toggle source

    # File lib/chef/mixin/template.rb, line 191
    def line_number
      @line_number ||= $1.to_i if original_exception.backtrace.find {|line| line =~ /\(erubis\):(\d+)/ }
    end

message() click to toggle source

    # File lib/chef/mixin/template.rb, line 187
    def message
      @original_exception.message
    end

source_listing() click to toggle source

    # File lib/chef/mixin/template.rb, line 199
    def source_listing
      @source_listing ||= begin
        lines = @template.split(/\n/)
        if line_number
          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
        else
          beginning_line = 0
          source_size    = lines.length
        end
        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() click to toggle source

    # File lib/chef/mixin/template.rb, line 195
    def source_location
      "on line ##{line_number}"
    end

to_s() click to toggle source

    # File lib/chef/mixin/template.rb, line 220
    def to_s
      "\n\n#{self.class} (#{message}) #{source_location}:\n\n" +
        "#{source_listing}\n\n  #{original_exception.backtrace.join("\n  ")}\n\n"
    end