Actions
Bug #21954
closedNoMethodError instead of Gem::LoadError on gem activation problem in Ruby 4.0.2
Bug #21954:
NoMethodError instead of Gem::LoadError on gem activation problem in Ruby 4.0.2
Description
I'm seeing a regression in Ruby 4.0.2 when there is a gem activation problem.
Install two versions of a gem, where one version has a file the other doesn't. One example here is rack:
$ gem install rack --version '< 3'
$ gem install rack
Force activation of the version that doesn't have the file, and then require the file and rescue LoadError:
gem 'rack', '< 3'
begin
require 'rack/headers'
rescue LoadError
end
In previous versions of Ruby, the Gem::LoadError would be correctly rescued, and you would get no output. In Ruby 4.0.2, you get a NoMethodError raised:
/usr/local/lib/ruby/4.0/rubygems.rb:196:in 'Gem.try_activate': undefined method 'name' for nil (NoMethodError)
spec ||= Gem::Specification.find_by_name(spec.name)
^^^^^
from /home/jeremy/gem-activate-problem.rb:4:in 'Kernel#require'
from /home/jeremy/gem-activate-problem.rb:4:in '<main>'
/usr/local/lib/ruby/4.0/rubygems/specification.rb:2170:in 'Gem::Specification#check_version_conflict': can't activate rack-3.2.4, already activated rack-2.2.21 (Gem::LoadError)
from /usr/local/lib/ruby/4.0/rubygems/specification.rb:1379:in 'Gem::Specification#activate'
from /usr/local/lib/ruby/4.0/rubygems.rb:193:in 'Gem.try_activate'
from /home/jeremy/gem-activate-problem.rb:4:in 'Kernel#require'
from /home/jeremy/gem-activate-problem.rb:4:in '<main>'
/home/jeremy/gem-activate-problem.rb:4:in 'Kernel#require': cannot load such file -- rack/headers (LoadError)
from /home/jeremy/gem-activate-problem.rb:4:in '<main>'
Same behavior on both OpenBSD and Linux.
Updated by hsbt (Hiroshi SHIBATA) about 17 hours ago
- Status changed from Open to Assigned
- Assignee set to hsbt (Hiroshi SHIBATA)
Updated by hsbt (Hiroshi SHIBATA) about 13 hours ago
@jeremyevans0 (Jeremy Evans) Thank you for your report. I confirmed this.
This issue was introduced RubyGems 4.0.5.
I will fix this at https://github.com/ruby/rubygems/pull/9404 and release RubyGems 4.0.9 with this fix at next week.
Updated by hsbt (Hiroshi SHIBATA) about 12 hours ago
- Status changed from Assigned to Closed
Actions