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

Failure/Error: require 'json-schema-rspec', cannot load such file -- multi_json #448

Closed
nbibler opened this issue Dec 10, 2020 · 6 comments

Comments

@nbibler
Copy link

nbibler commented Dec 10, 2020

In Ruby 2.7.2, Rubygems 3.2.0, and Bundler 2.2.0, the multi_json check fails in projects which do not have a multi_json dependency in their dependency tree.

https://github.com/ruby-json-schema/json-schema/blob/2f95d53d62428d603601a1346d6e12a70e7a505d/lib/json-schema.rb#L3-L4

When executed under Bundler, the application Rubygems are isolated to only those in the dependency tree. The Rubygems check performed above (Gem::Specification::find_all_by_name('multi_json').any?) returns true even though the Rubygem is not available to the application to load (requiring it results in a LoadError).

Rather than asking Rubygems if the library exists, it is more common to simply attempt to load the library and handle a LoadError. See Rails, for examples.

@obfuscoder
Copy link

obfuscoder commented Dec 11, 2020

This problem has popped up in one of our projects as well since yesterday. We use ruby 2.5.5 in that project. Not sure yet why it started appearing.

@lionelperrin
Copy link

It is likely that this issue happens because the gem multi_json is present on your system. The test Gem::Specification::find_all_by_name('multi_json').any? thus returns true but the gem cannot be loaded by bundler because the dependency to this gem is not declared.

@nbibler
Copy link
Author

nbibler commented Jan 4, 2021

@lionelperrin: Agreed.

Ultimately, this library is using Gem::Specification to determine if multi_json is available to be used. That check is incorrect, as you've noted. While the gem may be installed, Bundler may not make it available to the running application, based on the application's Gemfile. Because this check is wrong, the application errors when multi_json is not available via the Gemfile (not checked here).

@owst
Copy link

owst commented Jan 7, 2021

We've encountered the same issue when upgrading rubygems to 3.2.X. I have (several versions of) multi_json installed, but my Gemfile does not list it. Rubygems 3.1.4 works, but 3.2.0 and 3.2.4 both error failing to require multi_json. I'll raise an issue to report the bug (or at least request clarification) with rubygems and link to this issue.

@owst
Copy link

owst commented Jan 23, 2021

FYI @nbibler this was caused by a bug in rubygems - the fix has been released in 3.2.5 (and 3.2.6 is now also available) upgrade with gem update --system 3.2.6

@nbibler
Copy link
Author

nbibler commented Jan 23, 2021

Thanks @owst!

@nbibler nbibler closed this as completed Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants