Class Limelight::DSL::BuildException
In: lib/limelight/dsl/build_exception.rb
Parent: Exception

An Exception used by many of the DSL Builders. Allows nice errors messages, with line numbers, to be printed.

Methods

Attributes

filename  [R] 
line_number  [R] 

Public Class methods

[Source]

    # File lib/limelight/dsl/build_exception.rb, line 14
14:       def initialize(filename, file_contents, e)
15:         @filename = filename
16:         @file_contents = file_contents
17:         @original_exception = e
18:         @line_number = find_line_number
19:         super(build_error_message)
20:         set_backtrace(e.backtrace)
21:       end

Public Instance methods

[Source]

    # File lib/limelight/dsl/build_exception.rb, line 36
36:       def build_error_message
37:         lines = @file_contents.split("\n")
38:         if @line_number
39:           start_line = @line_number - 4 < 0 ? 0 : @line_number - 4
40:           end_line = @line_number + 2 >= lines.size ? lines.size - 1: @line_number + 2
41:           message = "#{@filename}:#{@line_number}: #{@original_exception.message}"
42:           message << "\n\t----- #{@filename} lines #{start_line + 1} - #{end_line + 1} -----"
43:           (start_line..end_line).each do |i|
44:             message << "\n\t#{i == @line_number - 1 ? "*": " "} #{i+1}: #{lines[i]}"
45:           end
46:         else
47:           message = "#{@filename}:? : #{@original_exception.message}"
48:         end
49:         message << "\n"
50:         return message
51:       end

[Source]

    # File lib/limelight/dsl/build_exception.rb, line 23
23:       def find_line_number
24:         lines = [@original_exception.message].concat @original_exception.backtrace
25:         line_number = nil
26:         lines.each do |line|
27:           match = line.match(/\(eval\):(\d+):/)
28:           if (match)
29:             line_number = match[1].to_i
30:             break
31:           end
32:         end
33:         return line_number
34:       end

[Validate]