Sha256: 88de06c400cd9cd42e6c9a5e6ff6db8caac08eed967e7125a4abbe21702ce032

Contents?: true

Size: 1.53 KB

Versions: 8

Compression:

Stored size: 1.53 KB

Contents

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
      @line = line
      @pos = pos
    end
    def to_s
      msg = super
      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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-3.3.2 lib/puppet/error.rb
puppet-3.3.1 lib/puppet/error.rb
puppet-3.3.1.rc3 lib/puppet/error.rb
puppet-3.3.1.rc2 lib/puppet/error.rb
puppet-3.3.1.rc1 lib/puppet/error.rb
puppet-3.3.0 lib/puppet/error.rb
puppet-3.3.0.rc3 lib/puppet/error.rb
puppet-3.3.0.rc2 lib/puppet/error.rb