NatLabRockies / NatLabRockies/OpenStudio
Cannot `require 'bundler'` when we are using --bundle flag and --bundle_path flag
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 646
- Forks
- 237
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 10
Description
Similar to #5161 , the issue about
'ArgumentError: Trying to register Bundler::GemfileError for status code 4 but Bundler::GemfileError is already registered'
The way I reproduce the issue:
//generate an empty Gemfile and install it
In NREL/openstudio:3.9.0
mkdir debug
cd debug
touch Gemfile
bundle _2.4.10_ install --path "./gems"
//run openstudio with --bundle --bundle_path flags with require bundler
openstudio --bundle "./Gemfile" --bundle_path "./gems" -e "require 'bundler'"
It will raise exception:
Warn: Bundle activated but ENV['BUNDLE_WITHOUT'] is not set
Info: Setting BUNDLE_WITHOUT to 'test'
:/ruby/3.2.0/gems/bundler-2.4.10/lib/bundler/vendor/fileutils/lib/fileutils.rb:183: warning: already initialized constant Bundler::FileUtils::VERSION
:/ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:183: warning: previous definition of VERSION was here
:/ruby/3.2.0/gems/bundler-2.4.10/lib/bundler/vendor/fileutils/lib/fileutils.rb:2165: warning: already initialized constant Bundler::FileUtils::Entry_::S_IF_DOOR
:/ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2165: warning: previous definition of S_IF_DOOR was here
:/ruby/3.2.0/gems/bundler-2.4.10/lib/bundler/vendor/fileutils/lib/fileutils.rb:2461: warning: already initialized constant Bundler::FileUtils::Entry_::DIRECTORY_TERM
:/ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2461: warning: previous definition of DIRECTORY_TERM was here
:/ruby/3.2.0/gems/bundler-2.4.10/lib/bundler/vendor/fileutils/lib/fileutils.rb:2569: warning: already initialized constant Bundler::FileUtils::OPT_TABLE
:/ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2569: warning: previous definition of OPT_TABLE was here
:/ruby/3.2.0/gems/bundler-2.4.10/lib/bundler/vendor/fileutils/lib/fileutils.rb:2627: warning: already initialized constant Bundler::FileUtils::LOW_METHODS
:/ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2627: warning: previous definition of LOW_METHODS was here
:/ruby/3.2.0/gems/bundler-2.4.10/lib/bundler/vendor/fileutils/lib/fileutils.rb:2634: warning: already initialized constant Bundler::FileUtils::METHODS
:/ruby/3.2.0/bundler/vendor/fileutils/lib/fileutils.rb:2634: warning: previous definition of METHODS was here
terminate called after throwing an instance of 'RubyException'
what(): ArgumentError: Trying to register Bundler::GemfileError for status code 4 but Bundler::GemfileError is already registered
Aborted
Issue overview
Current Behavior
Expected Behavior
I think in the old release it will not block the execution of rb file from
openstudio --bundle "./Gemfile" --bundle_path "./installed_gems" "lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb"
The root cause is tracing back through:
"lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb" -> "urbanopt/geojson" -> "urbanopt/core" -> "openstudio/extension" -> "bundler"
Steps to Reproduce
Has mentioned above.
Possible Solution
I offered a bypass in openstudio/extension to avoid requiring bundler when there is Bundler constants.
in this commit:
https://github.com/NREL/openstudio-extension-gem/commit/9c1e2dacd0bb59260e9d9829655e20d9ce175be9
and it do fix the issue, but I am not sure how it should be handle gracefully.
Details
Environment
Some additional details about your environment for this issue (if relevant):
- Platform (Operating system, version):
- Version of OpenStudio (if using an intermediate build, include SHA):
Context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction using openstudio --bundle "./Gemfile" --bundle_path "./gems" -e "require 'bundler'" and trace the path from lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb through urbanopt/geojson, urbanopt/core, and openstudio/extension. Review the bypass in openstudio/extension commit 9c1e2dacd0bb59260e9d9829655e20d9ce175be9 and determine graceful Bundler handling. Done means the command no longer raises the duplicate registration error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100