Exception: Finitio::Error

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

Direct Known Subclasses

JsonSchema::Error, TypeError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, cause = nil) ⇒ Error

Returns a new instance of Error.



5
6
7
8
# File 'lib/finitio/errors.rb', line 5

def initialize(msg, cause = nil)
  super(msg)
  @cause = cause
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



9
10
11
# File 'lib/finitio/errors.rb', line 9

def cause
  @cause
end

Instance Method Details

#root_cause(sandbox = true) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/finitio/errors.rb', line 11

def root_cause(sandbox = true)
  # 1) no deeper cause, it's me
  return self if cause.nil?

  # 2) not a Finitio cause and sandbox
  return self if sandbox and not cause.is_a?(Error)

  # 3) cause may not go deeper
  return cause unless cause.respond_to?(:root_cause)

  # 4) delegate
  cause.root_cause
end