-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add debugging docs #6387
Add debugging docs #6387
Conversation
🤔 Usually I just put |
bundler/doc/development/DEBUGGING.md
Outdated
gem 'tiny_css' | ||
``` | ||
|
||
Put a `binding.pry` anywhere you want the debugger to break. Run your Bundler shell alias. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to recommend binding.pry
instead of "native" binding.irb
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because binding.irb
is a REPL and not a debugger 🤷♀️ It's nice, but you can't really interactive debug. I can add that to these docs as a tool to use though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth noting that you need pry-byebug
installed to get a full debugger rather than just a pry REPL. 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh, good call out. I forget what gems I have installed globally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's it. Some info is at https://github.com/rubygems/rubygems/blob/030e285881ac99608fe8a23121b80ce1ce14ed6e/bundler/doc/development/SETUP.md#debugging-with-pry. Instead of this "complex" setup, you can do just binding.irb
and you have basic IRB-like console. For debug console, you can use binding.break
(you need to require 'debug'
somehow from debug gem, which is distributed with Ruby if I remember well and there is no need to install additional dependency).
I prefer to prefer "native" Ruby tools :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the debug
gem was not included until Ruby 3.1, and we will be stuck supporting older rubies for some time still. Ruby 2.7 is not EOL until March 31 2023, and 3.0 is not EOL for another year after that.
I think it is valuable to document a debug
gem workflow for the future, but we need tools to allow debugging older rubies for at least the next 1-2 years. 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can install debug gem the same way you can install pry-byebug
for older Rubies. It supports Ruby 2.6+.
Anyway the whole discussion is good sign that this setup is not simple. Experienced developers can use their favourite tools, there is almost nothing specific. And for beginners it would be maybe better to point to some generic Ruby debugging tutorial where basics like puts debugging and real debuggers are explained. 🤔
On the other way, if you think @indirect this kind of guide is valuable in here, let's start somewhere. I'm ok with anything that works. I was just about share my experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on this convo, I reorganized the doc slightly and tried to add just enough info to get new maintainers started but would like to link out to other places for more learning. Do we care who/what we link to? Here are some options (not in the doc yet)
- REPL debugging more info: https://st0012.dev/whats-new-in-ruby-3-2-irb
- Prints debugging more info: https://medium.com/@calielrushton/puts-prints-and-more-printing-to-the-console-in-ruby-7830cdaace0a
- Interactive debugging more info: https://github.com/ruby/debug#how-to-use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a couple of comments. Debugging tips never hurt, thanks for documenting this!
bundler/doc/development/DEBUGGING.md
Outdated
|
||
## Debugging in tests | ||
|
||
Your best option is to print debug in the test suite. Put `puts` statements anywhere you want to see an object or variable and you'll see your `puts` in the console output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mainly use puts
debugging too! Sometimes printing caller_locations(0).join("\n")
helps to see what the stacktrace is at a given point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful, I'll add that to the list of examples
```bash | ||
cd tmp | ||
mkdir [name of directory for local testing] && cd [name of directory for local testing] | ||
dbundle init |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normally point directly to my working copy with something like /path/to/rubygems/bundle/exe/bundle
. These days once you land on a copy of Bundler, you never get out of it because we always use require_relative
, so messing with the $LOAD_PATH
should not be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so should we change the alias instructions in the setup doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind the current recommendation to set an alias, and it should also work just fine, I don't think you need to change anything. Just wanted to mention the way I do it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think everyone have different debugging habits :). I was using ruby -Ilib -s ./exe/bundle -- --version
and even today it is usually enough to just call ./exe/bundle
.
But indeed, dbundle
is mentioned at various places. It is ok to keep it in here as well.
It sounds like there are multiple ways to test locally which don't match up with what we currently recommend to new maintainers in SETUP.md. Is the alias a totally bad idea? And should we update that doc too? |
|
||
To use REPL, place a `binding.irb` wherever you'd like to take a look around. An interactive `irb` console will open when your code gets to your breakpoint. | ||
|
||
To learn more about using IRB, [TODO: link to doc] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe https://github.com/ruby/irb#the-bindingirb-breakpoint
?
224bd3b
to
d0c9b01
Compare
Merge queue setting changed
Add debugging docs (cherry picked from commit 9101d15)
What was the end-user or developer problem that led to this PR?
Figuring out how to set up test cases and debug for a new maintainer is hard and there aren't existing docs to refer to. I had a call with @indirect and he walked me through how he debugs the Bundler code. This doc is a starting point for how to debug various test cases.
What is your fix for the problem, implemented in this PR?
Make sure the following tasks are checked