19
votes

When I set a breakpoint with Byebug in Rails, I sometimes want it to finish executing, but the guide on github says to use exit which also exits Pry. Typing continue repeatedly can be annoying if the breakpoint is in a loop.

Is there anyway to stop byebug without exiting the Rails console?

10
You can try the command "abort", it will abort the current executionsaadlulu

10 Answers

28
votes

When running byebug under the Rails console or in Rails' server I usually quit only byebug by hitting Ctrl+D.

The catch with this approach is, if you do this in Rails' server then Byebug will not stop and debug the next time it hits a byebug statement in your code anywhere. But it works perfectly in the Rails console.

6
votes

Try !!!. It works on pry gem, but not sure if it does on byebug.

2
votes

Well this isn't the most elegant solution but it works for me so far.

If you have a base controller in your rails application you can add an accessor to hold a variable saying whether you want debugging to happen or not:

attr_accessor :debugging

Then add/modify initializer to set the variable to true on each request (or each time there is an instance created for that object):

def initialize
  @debugging=true
  super
end

And finally, always use the byebug call with a conditional wherever you want this behavior:

byebug if debugging

Then when you are at the IRB console and you want to exit the debugger but continue executing the code you just set the variable:

@debugging=false; finish

You could even encapsulate this in a helper or do some OOP magic but this is a good starting point. Nice thing is that if you repeat the request you'll get the standard behavior again unless you set the variable to false again.

1
votes

Typing finish in the console exits byebug, without closing pry/rails console/rails server.

Ctrl + D also works.

0
votes

Go to your code and remove byebug and save, then in the buybug terminal write continue then press enter.

Tadaaa your app will continue and you will exit byebug all without closing your app.

0
votes
(byebug) quit
Really quit? (y/n) y
user ~

The only one that works quickly and without issues for me so far.

0
votes

abort should abort the execution and bring you back to your server or console.

If you've been in the debugger for a while, the server might start performing much slower. If this is the case, using exit to exit both byebug and the server, then restarting might still be the better option.

0
votes

If you want to exit a loop try skip.

It'll runs until the next breakpoint as long as it is different from the current one.

Then, once you are out of the loop you can continue.

-1
votes

Remove "debugger from your code and type in "finish" in console