Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use better_errors as debugger?

Is it possible to use the excellent better_errors gem as a debugger?

In other words, can I add code to make it drop into the better_errors "error" page, poke around, inspect things, and then continue?

I can add a bogus error or a raise, but then I can't "continue".

Yes, I know I can use debugger or pry, but the better_errors interface is superior, contains all sorts of request & stack info, and I can code/debug with 2 windows open instead of 3.

like image 546
jordanpg Avatar asked Jul 13 '13 00:07

jordanpg


3 Answers

Or or.... if you really need too.

Just put: raise 'something' and raise an arbitrary error wherever you need it and then you have your REPL there.

like image 182
Richard Ortega Avatar answered Sep 23 '22 07:09

Richard Ortega


No, it's built around the error page. And the call-stack snapshot it takes is from the last exception.

like image 45
horseyguy Avatar answered Sep 22 '22 07:09

horseyguy


Look at the binding_of_caller gem to use in conjunction with better_errors. Take 8 minutes and watch RailsCasts #402 for a demo using both gems together. It won't get you debug stepping or watchpoint setting, but it will certainly allow you to inspect and poke around local and instance variables in any stack frame (each with its own REPL).

From the README:

Using binding_of_caller we can grab bindings from higher up the call stack and evaluate code in that context. Allows access to bindings arbitrarily far up the call stack, not limited to just the immediate caller.

Be sure to only use it in your development environment, however. You should have the following in your Gemfile.

group :development do
  gem 'better_errors'
  gem 'binding_of_caller'
end
like image 27
cmh Avatar answered Sep 23 '22 07:09

cmh