lib/finitio/errors.rb in finitio-0.4.1 vs lib/finitio/errors.rb in finitio-0.5.0

- old
+ new

@@ -6,9 +6,23 @@ super(msg) @cause = cause end attr_reader :cause + 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 + end # class Error class TypeError < Error def initialize(msg, cause = nil, location = nil)