Sha256: c3f4e6f5548bc267b05eedc9cb3a9d5df6bd20861a32b155bf2f7a7973350715

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# Wrapper meant for NativeExceptions that wrap exceptions from Cascading.  The
# trouble is that the combined stack traces are so long, printing them case
# actually omit locations in the cascading.jruby or application code that
# matter, leaving you with no information about the source of the error.  This
# class just swallows all the nested exceptions, printing their message, while
# giving you a direct route into JRuby code to the cause of the problem.
class CascadingException < StandardError
  def initialize(native_exception, message)
    @ne = native_exception
    super("#{message}\n#{trace_causes(@ne, 1)}")
  end

  def cause(depth)
    fetch_cause(@ne, depth)
  end

  private

  def fetch_cause(ne, depth)
    return ne if depth <= 1
    fetch_cause(ne.cause, depth - 1)
  end

  def trace_causes(ne, depth)
    return unless ne
    trace = "Cause #{depth}: #{ne}\n"
    trace += ne.stack_trace.map { |e| "  at #{e.class_name}.#{e.method_name}(#{e.file_name}:#{e.line_number})" }.join("\n") + "\n" if ne.respond_to?(:stack_trace)
    trace += "#{trace_causes(ne.cause, depth + 1)}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cascading.jruby-0.0.4 lib/cascading/cascading_exception.rb