summaryrefslogtreecommitdiffstats
path: root/lib/puppet/error.rb
blob: 7be84d57371df296b424f2d7de789576d7fc7df5 (plain)
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
module Puppet # :nodoc:
    # The base class for all Puppet errors.  We want to make it easy to add
    # line and file information.  This probably isn't necessary for all
    # errors, but...
    class Error < RuntimeError
        attr_accessor :line, :file

        def backtrace
            if defined?(@backtrace)
                return @backtrace
            else
                return super
            end
        end

        def initialize(message, line = nil, file = nil)
            @message = message

            @line = line if line
            @file = file if file
        end

        def to_s
            str = nil
            if self.file and self.line
                str = "#{@message} at #{@file}:#{@line}"
            elsif self.line
                str = "#{@message} at line #{@line}"
            elsif self.file
                str = "#{@message} in #{self.file}"
            else
                str = @message.to_s
            end

            str
        end
    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
    end
end