How do I get ruby to print a full backtrace instead of a truncated one?

前端 未结 10 1605
-上瘾入骨i
-上瘾入骨i 2020-12-12 12:00

When I get exceptions, it is often from deep within the call stack. When this happens, more often than not, the actual offending line of code is hidden from me:



        
10条回答
  •  无人及你
    2020-12-12 12:50

    One liner for callstack:

    begin; Whatever.you.want; rescue => e; puts e.message; puts; puts e.backtrace; end
    

    One liner for callstack without all the gems's:

    begin; Whatever.you.want; rescue => e; puts e.message; puts; puts e.backtrace.grep_v(/\/gems\//); end
    

    One liner for callstack without all the gems's and relative to current directory

    begin; Whatever.you.want; rescue => e; puts e.message; puts; puts e.backtrace.grep_v(/\/gems\//).map { |l| l.gsub(`pwd`.strip + '/', '') }; end
    

提交回复
热议问题