Exception: Slinky::SlinkyError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/slinky/errors.rb

Overview

Common base class for all Slinky errors

Defined Under Namespace

Classes: NoContinuationError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#continuationObject

Returns the value of attribute continuation.



8
9
10
# File 'lib/slinky/errors.rb', line 8

def continuation
  @continuation
end

Class Method Details

.batch_errorsObject

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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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) ⇒ Object

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



22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Method Details

#continueObject

Continue where we left off



11
12
13
14
# File 'lib/slinky/errors.rb', line 11

def continue
  raise NoContinuationError unless continuation.respond_to?(:call)
  continuation.call
end

#messagesObject



16
17
18
# File 'lib/slinky/errors.rb', line 16

def messages
  [message]
end