22

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?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303

9 Answers9

34

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Jagjot
  • 5,816
  • 2
  • 24
  • 41
7

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

Vic
  • 1,512
  • 17
  • 25
2

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.

Gustavo Rubio
  • 10,209
  • 8
  • 39
  • 57
2

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.

borjagvo
  • 1,802
  • 2
  • 20
  • 35
1

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

Ctrl + D also works.

Rich
  • 590
  • 7
  • 20
0

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.

Mohammed
  • 2,215
  • 1
  • 9
  • 8
0

Try continue or finish

Source: https://edgeguides.rubyonrails.org/debugging_rails_applications.html#resuming-execution

-1

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

Ionut Milas
  • 318
  • 1
  • 11
  • 1
    Tried removing 'byebug' from the code but it kept breaking afterwards anyway as if it were there. Same behavior trying 'continue' and 'finish' commands. –  Jun 08 '15 at 18:39
  • This won't work. The code won't be reloaded until you exit the console. – the Tin Man Apr 06 '16 at 21:53
  • Not sure what the removing debuger is for, but typing `finish` in the byebug interface exited byebug without closing the rails console. – Rich Sep 15 '18 at 16:52
-1
(byebug) quit
Really quit? (y/n) y
user ~

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

Rich Steinmetz
  • 1,020
  • 13
  • 28