bundler errors using debug gem
Hi folks, thanks for this great extension.
I am trying to use it with my project.
My Project has a Gemfile like this:
source "https://rubygems.org"
ruby "~> 3.1"
... (lots of gems)
group :local do
gem "debug", require: false
end
... (more gems)
While starting ruby-lsp I get an error in the output panel of vscode-ruby-lsp:
>> Running `bundle install`...
ERROR>
ERROR> [!] There was an error parsing `Gemfile`: You cannot specify the same gem twice coming from different sources.
ERROR> You specified that debug (>= 0) should come from an unspecified source and locally installed gems
ERROR> . Bundler cannot continue.
ERROR>
ERROR> # from /Users/tono/Documents/Promotional Ideas/Lufthansa/Daisy/code/.ruby-lsp/Gemfile:6
ERROR> # -------------------------------------------
ERROR> # gem "ruby-lsp", require: false, group: :development, source: "https://rubygems.org"
ERROR> > gem "debug", require: false, group: :development, platforms: :mri, source: "https://rubygems.org"
ERROR> # -------------------------------------------
>> `bundle install` exited with code 4
When I add , source: "https://rubygems.org" to the debug gem in my gemfile, I still get an error, but bundler finishes and the extension is usable:
>> Running `bundle install`...
ERROR> Your Gemfile lists the gem debug (>= 0) more than once.
ERROR> You should probably keep only one of them.
ERROR> Remove any duplicate entries and specify the gem only once.
ERROR> While it's not a problem now, it could cause errors if you change the version of one of them later.
That might be a problem of Bundler, I am not sure. It might also be related to Shopify/ruby-lsp#1555 Perhaps it makes sense to detect of debug is already installed and not add it twice.
For now, I am just adding the source, but I would like to understand why this is required, or if there might be a better solution.
Hello! Thank you for the kind words.
The debug gem shouldn't have been added to the custom bundle indeed. I believe you might have uncovered two issues:
- The technique used by Shopify/ruby-lsp#1555 may not catch gems if they are in non-standard gemfile groups
- The second part does seem to be a bug in bundler. Both
debugentries are already coming from the same source, explicitly adding it as an option shouldn't be required
I experienced the same problem. My Gemfile has the "debug" gem included in the [:development, :testing] group. I had to add the source option to make the service start.
@tonklon I'm having some trouble reproducing this. Could you tell me:
- The version of bundler in use
- The contents of the
.bundle/configfile, if it exists within the project directory. (you can remove anything sensitive).
@steveclarke maybe you can share the above?
@andyw8
In the process of checking my codebase I backed out the source attribute from my "gem 'debug'" statement to see if the problem still existed and it works now.
Well, I should say I receive the message when my dev container is first rebuilt, but a "Reload Window" command results in the extension installing supporting gems and running.
So it may be dev container related, but I'm pretty sure a few days ago when I was struggling with this, I couldn't get it to work no matter how many times I restarted the dev container. In the meantime some other dependencies may have been updated.
Sorry I'm not of any more help than this, but at least it seems resolved for me for now. I'll post here again if I see it come back.
Bundler version 2.4.10
no .bundle/config
Running in Dev Container
I'll close for now, please re-open if you have further problems.
This also happens to me. Ruby 3.1.4, Bundler 2.3.10 (upgrading to 2.4.12 did not fix it).
If I add source: "https://rubygems.org" to the debug line in my Gemfile then bundling succeeds with a warning:
Your Gemfile lists the gem debug (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
The debug gem is in a group :development, :test block in the Gemfile. Moving it to group :development didn't work.
🚨 restarting VS Code after seeing errors about Ruby 3.0 (3.1 was an upgrade today) fixed the problem. The debug gem is no longer added to .ruby-lsp/Gemfile
fwiw "Ruby Version Manager" is set to auto, and is using rbenv
So, uh, never mind? Hopefully this helps someone else.
I also have this problem. Basic Rails 7 rails new setup, installed the Ruby LSP extension, same error as above. I commented out the gem "debug", platforms: %i[mri mingw x64_mingw] line in my Gemfile under group :development, :test do and reloaded VSCode and Ruby LSP activated. Afterwards I was able to uncomment the debug line and it continues to activate on launch afterwards.
My environment BUNDLE_PATH is set to ".bundle" Using ASDF as my version manager Using Ruby 3.2.1
I can reproduce the issue running gem uninstall ruby-lsp and gem uninstall debug and hitting F1, Developer: Reload Window.
Thank you for the reports, I will re-open for investigation.
I am on vacation and not able to provide further information at that time or test at this time. Thanks to @granth and @wamonroe for jumping in.
I used bundler version 2.4.6 when I found and reported the issue. An update of bundler to 2.4.12 did not change the behavior.
Moving the debug gem from the :local group to the :development group did not change the behavior.
There is no local bundle config. The only thing in the user config is a build flag for mysql2.
I am really not able to figure out the connection between the mentioned pull request and this error, but I can confirm the error is solved in the latest version.
Thanks a lot.