class Pry::Command::Wtf

Public Instance Methods

options(opt) click to toggle source
# File lib/pry/commands/wtf.rb, line 22
def options(opt)
  opt.on :v, :verbose, "Show the full backtrace"
end
process() click to toggle source
# File lib/pry/commands/wtf.rb, line 26
def process
  raise Pry::CommandError, "No most-recent exception" unless exception

  output.puts "#{bold('Exception:')} #{exception.class}: #{exception}\n--"
  if opts.verbose?
    output.puts with_line_numbers(backtrace)
  else
    output.puts with_line_numbers(backtrace.first(size_of_backtrace))
  end

  if exception.respond_to? :cause
    cause = exception.cause
    while cause
      output.puts "#{text.bold('Caused by:')} #{cause.class}: #{cause}\n--"
      if opts.verbose?
        output.puts with_line_numbers(cause.backtrace)
      else
        output.puts with_line_numbers(cause.backtrace.first(size_of_backtrace))
      end
      cause = cause.cause
    end
  end
end

Private Instance Methods

backtrace() click to toggle source
# File lib/pry/commands/wtf.rb, line 60
def backtrace
  exception.backtrace
end
exception() click to toggle source
# File lib/pry/commands/wtf.rb, line 52
def exception
  _pry_.last_exception
end
size_of_backtrace() click to toggle source
# File lib/pry/commands/wtf.rb, line 64
def size_of_backtrace
  [captures[0].size, 0.5].max * 10
end
with_line_numbers(bt) click to toggle source
# File lib/pry/commands/wtf.rb, line 56
def with_line_numbers(bt)
  Pry::Code.new(bt, 0, :text).with_line_numbers.to_s
end