class Airbrake::NestedException

A class that is capable of unwinding nested exceptions and representing them as JSON-like hash.

@api private @since v1.0.4

Constants

MAX_NESTED_EXCEPTIONS

@return [Integer] the maximum number of nested exceptions that a notice

can unwrap. Exceptions that have a longer cause chain will be ignored

Public Class Methods

new(exception) click to toggle source
# File lib/airbrake-ruby/nested_exception.rb, line 12
def initialize(exception)
  @exception = exception
end

Public Instance Methods

as_json() click to toggle source
# File lib/airbrake-ruby/nested_exception.rb, line 16
def as_json
  unwind_exceptions.map do |exception|
    { type: exception.class.name,
      message: exception.message,
      backtrace: Backtrace.parse(exception) }
  end
end

Private Instance Methods

unwind_exceptions() click to toggle source
# File lib/airbrake-ruby/nested_exception.rb, line 26
def unwind_exceptions
  exception_list = []
  exception = @exception

  while exception && exception_list.size < MAX_NESTED_EXCEPTIONS
    exception_list << exception
    exception = (exception.cause if exception.respond_to?(:cause))
  end

  exception_list
end