curriculum icon indicating copy to clipboard operation
curriculum copied to clipboard

Ruby: [Event Manager tutorial] `google-apis-civicinfo_v2` must be added to Gemfile to avoid LoadError during debugging with ruby-lsp

Open sometimescasey opened this issue 1 year ago • 5 comments

Checks

Describe your suggestion

I'm debugging in VSCode using ruby-lsp (0.13.4), and the Ruby LSP extension (v0.5.9).

Without a Gemfile, and executing in the Terminal using ruby lib/event_manager.rb, the line require 'google/apis/civicinfo_v2' (or google-apis-civicinfo_v2, both work) runs successfully.

However when using the debugger, this line causes a LoadError unless a Gemfile exists at the project root and contains the line gem 'google-apis-civicinfo_v2'. (upon hitting save Gemfile.lock auto-populates itself):

#<LoadError: cannot load such file -- google/apis/civicinfo_v2>

I'm opening an issue because this took me a very long time to figure out, and the tutorial does not make use of a Gemfile. It's not an obvious solution for someone who is new to Ruby, and part of my reason for filing this issue is so that it will pop up on Google for anyone else who runs into the same.

I'm not sure if this is a ruby-lsp specific issue.

This is also the first tutorial which makes use of a gem that needs to be installed, so it's quite possible to never encounter this in all prior lessons.

Path

Ruby / Rails

Lesson Url

https://www.theodinproject.com/lessons/ruby-event-manager

(Optional) Discord Name

sometimescasey

(Optional) Additional Comments

I'm not sure what the fix is (or if we really need one? I guess we could add a small note to the tutorial?), but I do want the issue to exist in case others run into the same.

sometimescasey avatar Feb 02 '24 22:02 sometimescasey

FWIW it looks like https://github.com/TheOdinProject/curriculum/pull/27128 will probably help with this, so feel free to close this issue if you think that is a sufficient solution.

sometimescasey avatar Feb 02 '24 23:02 sometimescasey

I'm not a maintainer but I am very interested in everything Ruby LSP in the TOP context 😆

This issue seems to stem from the fact that Ruby LSP's debugging is by default (not sure if always) using bundle exec and as such it looks for a Gemfile. Personally at the moment I'd suggest using the rdbg extension for debugging - it comes from the Ruby people and debug gem creator & maintainer himself and others and by default it runs with just ruby, so it can grab globally installed gems. Which perhaps is not the best practice but it is the simplest practice.

I was able to reproduce your issue AND also find another issue with Ruby LSP which does not surprise me in the slightest.

scheals avatar Feb 03 '24 09:02 scheals

Thank you for the detailed issue and for bringing attention to this 🙌

FWIW it looks like #27128 will probably help with this, so feel free to close this issue if you think that is a sufficient solution.

The lesson in that PR will definitely help, but I think the instructions for Event Manager will still need updating so that learners know to use a Gemfile. I'll leave this open, but we won't be able to work on it until #27128 is merged (after which, we can begin assuming that learners understand basics around bundler and Gemfiles).

Does that sound okay to you @sometimescasey ?

JoshDevHub avatar Feb 04 '24 05:02 JoshDevHub

Thanks @JoshDevHub @scheals ! Yes that all sounds good. Happy to help in whatever way I can :)

Quick note also that

gem install google-api-client

is no longer the recommended installation method:

*******************************************************************************
The google-api-client gem is deprecated and will likely not be updated further.

Instead, please install the gem corresponding to the specific service to use.
For example, to use the Google Drive V3 client, install google-apis-drive_v3.
For more information, see the FAQ in the OVERVIEW.md file or the YARD docs.
*******************************************************************************

So we may want to update this to

gem install google-apis-civicinfo_v2

whenever we get around to updating this tutorial.

sometimescasey avatar Feb 06 '24 00:02 sometimescasey

This issue is stale because it has had no activity for the last 30 days.

github-actions[bot] avatar Mar 08 '24 01:03 github-actions[bot]

@JoshDevHub now that #27128 is merged, does this still need work?

mao-sz avatar Sep 30 '24 18:09 mao-sz

@MaoShizhong

Nice call! This issue should be solved since the project now has users set up a Gemfile.

Closed by #27128

JoshDevHub avatar Sep 30 '24 20:09 JoshDevHub