class PrettyTrace::Handler

Public Instance Methods

disable() click to toggle source
# File lib/pretty_trace/handler.rb, line 21
def disable
  @enabled = false
end
enable() click to toggle source
# File lib/pretty_trace/handler.rb, line 8
def enable
  @enabled = true
  # :nocov: - this is actually covered through an external process
  at_exit do
    if @enabled and $! and !ignored.include? $!.class
      show_errors $!
      $stderr.reopen IO::NULL
      $stdout.reopen IO::NULL
    end
  end
  # :nocov:
end
enabled?() click to toggle source
# File lib/pretty_trace/handler.rb, line 25
def enabled?
  @enabled
end
options() click to toggle source
# File lib/pretty_trace/handler.rb, line 29
def options
  @options ||= default_options
end
options=(new_options) click to toggle source
# File lib/pretty_trace/handler.rb, line 33
def options=(new_options)
  @options = new_options
end

Private Instance Methods

default_options() click to toggle source
# File lib/pretty_trace/handler.rb, line 66
def default_options
  { filter: [] }
end
ignored() click to toggle source
# File lib/pretty_trace/handler.rb, line 39
def ignored
  # :nocov:
  [ SystemExit ]
  # :nocov:
end
show_errors(exception) click to toggle source
# File lib/pretty_trace/handler.rb, line 45
def show_errors(exception)
  # :nocov:
  backtrace = StructuredBacktrace.new exception.backtrace, options

  puts "\n#{backtrace}" unless backtrace.empty?

  message = exception.message
  if message.empty?
    puts "\n%{blue}#{exception.class}%{reset}\n" % colors
  else
    puts "\n%{blue}#{exception.class}\n%{red}#{message}%{reset}\n" % colors
  end

  if options[:debug_tip] and ENV['PRETTY_TRACE'] != 'full'
    puts "\nTIP: Run with %{cyan}PRETTY_TRACE=full%{reset} (or %{cyan}off%{reset}) for debug information" % colors
  end

  $stdout.flush
  # :nocov:
end