class R10K::Error

An error class that accepts an optional hash and wrapped error message

Attributes

original[RW]

Public Class Methods

new(mesg, options = {}) click to toggle source

@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

Calls superclass method
# File lib/r10k/errors.rb, line 32
def initialize(mesg, options = {})
  super(mesg)

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

  @options = options
end
wrap(original, mesg, options = {}) click to toggle source

Generate a wrapped exception

@param original [Exception] The exception to wrap @param mesg [String] @param options [Hash]

@return [R10K::Error]

# File lib/r10k/errors.rb, line 17
def self.wrap(original, mesg, options = {})
  new(mesg, options).tap do |e|
    e.set_backtrace(caller(4))
    e.original = original
  end
end

Protected Instance Methods

indent(str, level = 4) click to toggle source
# File lib/r10k/errors.rb, line 56
def indent(str, level = 4)
  prefix = ' ' * level
  str.gsub(/^/, prefix)
end
structure_exception(name, exc) click to toggle source
# File lib/r10k/errors.rb, line 45
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