Make Byebug finish executing without exiting Pry

2020-08-09 09:27发布

问题:

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?

回答1:

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.



回答2:

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



回答3:

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.



回答4:

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

Ctrl + D also works.



回答5:

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.



回答6:

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