Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails debugging flag (-u) not working #2

Closed
bitaxis opened this issue Apr 30, 2013 · 5 comments
Closed

Rails debugging flag (-u) not working #2

bitaxis opened this issue Apr 30, 2013 · 5 comments

Comments

@bitaxis
Copy link

bitaxis commented Apr 30, 2013

So I finally got a chance to try out byebug for debugging my Ruby 2.0.0 Rails 3.2.x apps, and like the fact next does not behave like step. However, I noticed that if I uninstalled the debugger gem and then installed byebug, and fired up WEBrick, I get the following error:

$ rails server -u
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
Exiting

But if I put the line gem "debugger" back into my Gemfile before gem "byebug" and run bundle install, then it works just fine.

@deivid-rodriguez
Copy link
Owner

HI @bitaxis, thanks for the feedback! I got that same issue when I first started developing and using byebug, but didn't investigate further. I am pretty sure what I did was just starting the server in normal mode (without the -uflag) and it worked just right without having to install debugger.

Could you try that and let me know whether it works for you?

@bitaxis
Copy link
Author

bitaxis commented Apr 30, 2013

@deivid-rodriguez Yes. If I leave out the -u flag, then the error goes away, and I can still break into my code using byebug. I also verified that I can break into my code using the debugger gem also. Which begs the question, what is the -u flag for exactly?

Anyhow, I will close this ticket now. Thanks!

@bitaxis bitaxis closed this as completed Apr 30, 2013
@deivid-rodriguez
Copy link
Owner

That's a good question. If I find out I will let you know! :)

@deivid-rodriguez
Copy link
Owner

Hi again @bitaxis! I investigated this today. Some answers:

what's the -u flag for exactly?

Starting the server in debugging mode allows you to have full stack information in your rails application. That means that the debugger is started when the server is started. If you don't use the debugging flag, the debugger will be started when the byebug or debugger call is issued inside your application, so you will only have debug information from that point on.
That's the reason why the first time you break into your code, if you issue the command where, the backtrace will only contain one entry, because byebug was just started. On the other hand, if you use the -u flag you will get full stack information from the beggining.

does the -u flag work with byebug?

No, it doesn't. Rails specifically requires and starts debugger (see here). To workaround this, you can monkeypatch rails by adding a file config/initializers/rack_byebug.rb (for example) to your app with the following contents:

module Rails
  module Rack
    class Debugger
      def initialize(app)
        @app = app

        # clear ARGV so that rails server options aren't passed to IRB
        ARGV.clear

        require 'byebug'

        ::Byebug.start
        puts "=> Byebug enabled"
      rescue LoadError
        puts "You're missing the 'byebug' gem. Add it to your Gemfile, bundle " \
               "it and try again."
        exit(1)
      end

      def call(env)
        @app.call(env)
      end
    end
  end
end

I will probably include a similar monkeypatch inside byebug but in the meantime this should work.

deivid-rodriguez pushed a commit that referenced this issue Jun 2, 2013
@deivid-rodriguez
Copy link
Owner

Since byebug 1.5.0 rails debugging flag is no longer necessary. Don't use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants