class Slinky::SlinkyError

Common base class for all Slinky errors

Attributes

continuation[RW]

Public Class Methods

batch_errors() { || ... } click to toggle source

batches all SlinkyErrors thrown in the supplied block and re-raises them at the end of processing wrapped in a MultiError.

# File lib/slinky/errors.rb, line 38
def self.batch_errors
  errors = []
  result = nil
  begin
    result = yield
  rescue SlinkyError => e
    errors << e
    if e.continuation.respond_to?(:call)
      e.continue
    end
  end

  if !errors.empty?
    if errors.size == 1
      raise errors.first
    else
      raise MultiError, errors
    end
  end
  result
end
raise(exception = SlinkyError, string = nil, array = caller) click to toggle source

Raises an error with a continuation that allows us to continue with processing as if no error had been thrown

Calls superclass method
# File lib/slinky/errors.rb, line 22
def self.raise(exception = SlinkyError, string = nil, array = caller)
  if exception.is_a?(String)
    string = exception
    exception = SlinkyError
  end

  callcc do |cc|
    obj = string.nil? ? exception : exception.exception(string)
    obj.set_backtrace(array)
    obj.continuation = cc
    super obj
  end
end

Public Instance Methods

continue() click to toggle source

Continue where we left off

# File lib/slinky/errors.rb, line 11
def continue
  raise NoContinuationError unless continuation.respond_to?(:call)
  continuation.call
end
messages() click to toggle source
# File lib/slinky/errors.rb, line 16
def messages
  [message]
end