1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
module Puppet
# The base class for all Puppet errors. It can wrap another exception
class Error < RuntimeError
attr_accessor :original
def initialize(message, original=nil)
super(message)
@original = original
end
end
module ExternalFileError
# This module implements logging with a filename and line number. Use this
# for errors that need to report a location in a non-ruby file that we
# parse.
attr_accessor :line, :file, :pos
# May be called with 3 arguments for message, file, line, and exception, or
# 4 args including the position on the line.
#
def initialize(message, file=nil, line=nil, pos=nil, original=nil)
if pos.kind_of? Exception
original = pos
pos = nil
end
super(message, original)
@file = file unless (file.is_a?(String) && file.empty?)
@line = line
@pos = pos
end
def to_s
msg = super
@file = nil if (@file.is_a?(String) && @file.empty?)
if @file and @line and @pos
"#{msg} at #{@file}:#{@line}:#{@pos}"
elsif @file and @line
"#{msg} at #{@file}:#{@line}"
elsif @line and @pos
"#{msg} at line #{@line}:#{@pos}"
elsif @line
"#{msg} at line #{@line}"
elsif @file
"#{msg} in #{@file}"
else
msg
end
end
end
class ParseError < Puppet::Error
include ExternalFileError
end
class ResourceError < Puppet::Error
include ExternalFileError
end
# An error class for when I don't know what happened. Automatically
# prints a stack trace when in debug mode.
class DevError < Puppet::Error
include ExternalFileError
end
end
|