Sha256: 6662d858caf453aecb028b28ca312feee85ff110db04a384d53bcec705b540c8

Contents?: true

Size: 1.34 KB

Versions: 53

Compression:

Stored size: 1.34 KB

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

    protected

    def structure_exception(name, exc)
      struct = []
      struct << "#{name}:"
      if exc.respond_to?(:format)
        struct << indent(exc.format)
      else
        struct << indent(exc.message)
      end
      struct.join("\n")
    end

    def indent(str, level = 4)
      prefix = ' ' * level
      str.gsub(/^/, prefix)
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
r10k-3.12.1 lib/r10k/errors.rb
r10k-3.12.0 lib/r10k/errors.rb
r10k-3.11.0 lib/r10k/errors.rb
r10k-3.10.0 lib/r10k/errors.rb
r10k-3.9.3 lib/r10k/errors.rb
r10k-3.9.2 lib/r10k/errors.rb
r10k-3.9.1 lib/r10k/errors.rb
r10k-3.9.0 lib/r10k/errors.rb
r10k-3.8.0 lib/r10k/errors.rb
r10k-3.7.0 lib/r10k/errors.rb
r10k-3.6.0 lib/r10k/errors.rb
r10k-2.6.9 lib/r10k/errors.rb
r10k-3.5.2 lib/r10k/errors.rb
r10k-3.5.1 lib/r10k/errors.rb
r10k-3.5.0 lib/r10k/errors.rb
r10k-3.4.1 lib/r10k/errors.rb
r10k-2.6.8 lib/r10k/errors.rb
r10k-3.4.0 lib/r10k/errors.rb
r10k-3.3.3 lib/r10k/errors.rb
r10k-3.2.3 lib/r10k/errors.rb