Running solargraph gems crashes on benchmark gem
# solargraph version
0.54.5
# solargraph gems
Cache already exists for ast 2.4.2
Cache already exists for backport 1.2.0
Caching gem documentation for benchmark 0.4.0
/usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/yardoc.rb:19:in 'Dir.chdir': No such file or directory @ dir_chdir0 - /usr/lib/ruby/gems/3.4.0/gems/benchmark-0.4.0 (Errno::ENOENT)
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/yardoc.rb:19:in 'Solargraph::Yardoc.cache'
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/gem_pins.rb:58:in 'Solargraph::GemPins.build_yard_pins'
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/gem_pins.rb:17:in 'Solargraph::GemPins.build'
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/shell.rb:264:in 'Solargraph::Shell#do_cache'
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/shell.rb:141:in 'block in Solargraph::Shell#gems'
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/shell.rb:141:in 'Array#each'
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/lib/solargraph/shell.rb:141:in 'Solargraph::Shell#gems'
from /usr/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
from /usr/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
from /usr/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor.rb:538:in 'Thor.dispatch'
from /usr/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/base.rb:584:in 'Thor::Base::ClassMethods#start'
from /usr/lib/ruby/gems/3.4.0/gems/solargraph-0.54.5/bin/solargraph:5:in '<top (required)>'
from /usr/bin/solargraph:25:in 'Kernel#load'
from /usr/bin/solargraph:25:in '<main>'
# gem list | grep bench
benchmark (default: 0.4.0)
# pacman -F benchmark.rb
...
extra/ruby 3.4.3-2 [installed: 3.4.4-2]
usr/lib/ruby/3.4.0/benchmark.rb
I'm not terribly familiar with Arch Linux - any chance you could provide a recipe to reproduce this in Docker? Suspect that something is lying to us about the gem location in the Gem::Specification object we receive.
Yes, that seems to be the case: the gems that trip up solargraph are installed as part of the ruby package, which apparently are (sometimes?) installed under /usr/lib/ruby/3.4.0. But gems info thinks otherwise, which might be the root of the issue:
# gem info benchmark
*** LOCAL GEMS ***
benchmark (0.4.0)
Author: Yukihiro Matsumoto
Homepage: https://github.com/ruby/benchmark
Licenses: Ruby, BSD-2-Clause
Installed at (default): /usr/lib/ruby/gems/3.4.0
a performance benchmarking library
So, in this case:
gem info benchmarkstates install location as/usr/lib/ruby/gems/3.4.0benchmark.rbis actually here:/usr/lib/ruby/3.4.0/benchmark.rb
I filed this on the ruby package in Arch Linux here: https://gitlab.archlinux.org/archlinux/packaging/packages/ruby/-/issues/11
Sounds good. Regardless, I think we should add an exception handler and move onto the next gem, as Linux distributions definitely do move gems around when installed by system packages.
You could probably create a symlink to work around this for now.
Sure, but you should then definitely log an error, so it doesn't silently skip them. Another intermediate option is to check that other directory, but then that directory should be some sort of known system dir.
Like, check path specified by gem, if not found, check that system dir and if found log warning, and finally then if still not found log error.