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

Add debugging docs #6387

Merged
merged 6 commits into from
Mar 17, 2023
Merged

Add debugging docs #6387

merged 6 commits into from
Mar 17, 2023

Conversation

mercedesb
Copy link
Contributor

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?

  • Add DEBUGGING.md to document how to debug Bundler

Make sure the following tasks are checked

@simi
Copy link
Member

simi commented Feb 16, 2023

🤔 Usually I just put binding.irb in test and run that one test file or case individually. For integration testing I just run ruby setup.rb to install dev version locally or even run ruby -Ilib bin/gem locally to test gem command.

gem 'tiny_css'
```

Put a `binding.pry` anywhere you want the debugger to break. Run your Bundler shell alias.
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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. 👍🏻

Copy link
Contributor Author

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

Copy link
Member

@simi simi Feb 16, 2023

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 :)

Copy link
Member

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. 👍🏻

Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a 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!


## 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.
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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 :)

Copy link
Member

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.

@mercedesb
Copy link
Contributor Author

For integration testing I just run ruby setup.rb to install dev version locally or even run ruby -Ilib bin/gem locally to test gem command.

I normally point directly to my working copy with something like /path/to/rubygems/bundle/exe/bundle

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]
Copy link
Member

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?

@hsbt hsbt enabled auto-merge March 17, 2023 04:23
@hsbt hsbt force-pushed the mb-debugging-docs branch 2 times, most recently from 224bd3b to d0c9b01 Compare March 17, 2023 05:55
auto-merge was automatically disabled March 17, 2023 07:35

Merge queue setting changed

@hsbt hsbt enabled auto-merge March 17, 2023 07:57
@hsbt hsbt added this pull request to the merge queue Mar 17, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 17, 2023
@hsbt hsbt enabled auto-merge March 17, 2023 08:57
@hsbt hsbt added this pull request to the merge queue Mar 17, 2023
Merged via the queue into master with commit 9101d15 Mar 17, 2023
@hsbt hsbt deleted the mb-debugging-docs branch March 17, 2023 12:39
deivid-rodriguez pushed a commit that referenced this pull request Mar 20, 2023
Add debugging docs

(cherry picked from commit 9101d15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants