Sha256: 3c2d17ae9eb8c4adffbca1b2b0c4128c0e0e3cc21ec174035713899de17ade79

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# this one display full BT with code, at the end [no performance loss]

require 'rbconfig'
DOZE = Config::CONFIG['host_os'] =~ /mswin|mingw/

require File.dirname(__FILE__) + "/shared"

at_exit {
  if $! && !$!.is_a?(SystemExit) # SystemExit's are normal, not exceptional
    print "\n"
    print "\t" unless defined?($same_line)
    
    puts $!.inspect + ' ' + $!.to_s

    max = 0
    $!.backtrace.each{|bt_line| max = [bt_line.length, max].max}

    backtrace_with_code = $!.backtrace.map{ |bt_line|
      next if bt_line.include? 'bin/backtracer' # binary lines...
      if DOZE && bt_line[1..1] == ':'
        
        drive, file, line, junk = bt_line.split(":")
	#["C", "/dev/ruby/allgems/lib/allgems/GemWorker.rb", "91", "in `unpack'"]              
        file = drive + ":" + file
      else
        file, line, junk = bt_line.split(":")
      end
      line = line.to_i
      actual_line = Tracer.get_line(file, line)
     
      "%-#{max + 1}s #{"\n\t" unless defined?($same_line)}%s" % [bt_line, (actual_line.strip if actual_line)]
    }.compact
    puts backtrace_with_code
    puts # blank line
    # for some reason this can be nil...
    $!.set_backtrace [] if $! # avoid the original backtrace being outputted--though annoyingly it does still output its #to_s...
    
  else
    puts "(backtracer: no exception found to backtrace)" if $DEBUG
  end
  # exit! TODO I guess do this once ours isn't *so* ugly
  # I'm not sure it's safe to do that, in case there are other at_exit's [?]
  # TODO compare with that fella xray
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
backtracer-0.6.5 lib/backtracer.rb