module Pry::ExceptionHandler

@api private @since v0.13.0

Public Class Methods

handle_exception(output, exception, _pry_instance) click to toggle source

Will only show the first line of the backtrace.

# File lib/pry/exception_handler.rb, line 9
def handle_exception(output, exception, _pry_instance)
  if exception.is_a?(UserError) && exception.is_a?(SyntaxError)
    output.puts "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}"
  else
    output.puts standard_error_text_for(exception)
  end
end

Private Class Methods

cause_text(cause) click to toggle source
# File lib/pry/exception_handler.rb, line 37
def cause_text(cause)
  "Caused by #{cause.class}: #{cause}\n" \
  "from #{cause.backtrace.first}\n"
end
exception_text(exception) click to toggle source
# File lib/pry/exception_handler.rb, line 32
def exception_text(exception)
  "#{exception.class}: #{exception.message}\n" \
  "from #{exception.backtrace.first}\n"
end
standard_error_text_for(exception) click to toggle source
# File lib/pry/exception_handler.rb, line 19
def standard_error_text_for(exception)
  text = exception_text(exception)
  return text unless exception.respond_to?(:cause)

  cause = exception.cause
  while cause
    text += cause_text(cause)
    cause = cause.cause
  end

  text
end