Sha256: 2992987643b63f3af078d3ef06103b2e1050a1d43b73535f52e63dcef198fb21

Contents?: true

Size: 1.66 KB

Versions: 44

Compression:

Stored size: 1.66 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 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

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.8.0 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.7.3 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-retrospec-0.7.2 vendor/gems/puppet-3.7.3/lib/puppet/error.rb
puppet-3.7.4 lib/puppet/error.rb
puppet-3.7.4-x86-mingw32 lib/puppet/error.rb
puppet-3.7.4-x64-mingw32 lib/puppet/error.rb
puppet-3.7.3 lib/puppet/error.rb
puppet-3.7.3-x86-mingw32 lib/puppet/error.rb
puppet-3.7.3-x64-mingw32 lib/puppet/error.rb
puppet-3.7.2 lib/puppet/error.rb
puppet-3.7.2-x86-mingw32 lib/puppet/error.rb
puppet-3.7.2-x64-mingw32 lib/puppet/error.rb