Sha256: 4812dcac0dfa4301af48b0eb7dfb482c4f73bf09dce400933236d07e1ff5524b

Contents?: true

Size: 1015 Bytes

Versions: 9

Compression:

Stored size: 1015 Bytes

Contents

require 'r10k'

module R10K

  # An error class that accepts an optional hash and wrapped error message
  #
  class Error < StandardError
    attr_accessor :original

    # Generate a wrapped exception
    #
    # @param original [Exception] The exception to wrap
    # @param mesg [String]
    # @param options [Hash]
    #
    # @return [R10K::Error]
    def self.wrap(original, mesg, options = {})
      new(mesg, options).tap do |e|
        e.set_backtrace(caller(4))
        e.original = original
      end
    end

    # @overload initialize(mesg)
    #   @param mesg [String] The exception mesg
    #
    # @overload initialize(mesg, options)
    #   @param mesg [String] The exception mesg
    #   @param options [Hash] A set of options to store on the exception
    #
    # @options options [Array<String>] :backtrace
    def initialize(mesg, options = {})
      super(mesg)

      bt = options.delete(:backtrace)
      if bt
        set_backtrace(bt)
      end

      @options = options
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
r10k-2.2.2 lib/r10k/errors.rb
r10k-2.2.1 lib/r10k/errors.rb
r10k-2.2.0 lib/r10k/errors.rb
r10k-2.1.1 lib/r10k/errors.rb
r10k-2.1.0 lib/r10k/errors.rb
r10k-2.0.3 lib/r10k/errors.rb
r10k-2.0.2 lib/r10k/errors.rb
r10k-2.0.1 lib/r10k/errors.rb
r10k-2.0.0 lib/r10k/errors.rb