Sometimes I need to debug some unpleasant exception where its back trace is hidden or truncated, for example, ArgumentErrorwithout a stack trace.
I use to debug using beebug. The problem is that the byebug interpreter is REPL, so it is not possible to write multi-line code. I am trying to figure out how to make a built-in rescue and print the backtrace, i.e. I want a built-in, REPL compatible version
begin
....
rescue => e
puts e.backtrace.join("\n")
end
I tried
begin; my_crashing_method.call; rescue Exception => e; puts e.backtrace; end
But this line raises a SyntaxError
*** SyntaxError Exception: (byebug):1: syntax error, unexpected keyword_rescue
rescue Exception => e
^
I'm not sure what I am missing?
EDIT
The line above works fine on a regular IRB / Rails shell, but not from a byebug shell
ESO
begin my_crashing_method.call; rescue Exception => e; puts e.backtrace end
Stack trace completed successfully
Byebug
(byebug) begin; my_crashing_method.call; rescue Exception => e; puts e.backtrace
*** SyntaxError Exception: (byebug):1: syntax error, unexpected end-of-input
begin
^
nil
*** NameError Exception: undefined local variable or method `my_crashing_method' for #<StaticPagesController:0x007fae79f61088>
nil
*** SyntaxError Exception: (byebug):1: syntax error, unexpected keyword_rescue
rescue Exception => e
^
nil
*** NameError Exception: undefined local variable or method `e' for
nil