Module: LunaPark::Extensions::Exceptions::Substitutive::ClassMethods

Defined in:
lib/luna_park/extensions/exceptions/substitutive.rb

Instance Method Summary collapse

Instance Method Details

#substitute(origin) ⇒ Object

Substitute original exception with save original backtrace.

Examples:

bad case

class MyException < StandardError
  extend LunaPark::Extensions::Exceptions::Substitutive
end

  call_exceptional_lib!
rescue ExceptionalLib::SomeException => e
  raise MyException # => raised MyException with backtrace started from `raise MyException`
                    #      and not contained origin exception backtrace
                    #      that can be very painfull for debug
end

resolve

begin
  call_exceptional_lib!
rescue ExceptionalLib::SomeException => e
  raise MyException.substitute(e) # => raised MyException with backtrace started
                                  #      from library `raise ExceptionalLib::SomeException`
                                  #      so you can easily find out where exception starts
end


36
37
38
39
40
41
# File 'lib/luna_park/extensions/exceptions/substitutive.rb', line 36

def substitute(origin)
  new = new(origin.message)
  new.backtrace = origin.backtrace
  new.origin    = origin
  new
end