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

chruby reports exit status 0 under Bash, but still throws a Ruby exception when switching to mruby #477

Open
todd-a-jacobs opened this issue May 1, 2022 · 1 comment
Labels

Comments

@todd-a-jacobs
Copy link

Description

ruby-install sucessfully installs mruby-3.0.0 without errors. However, chruby reports a successful exit status under Bash, but still throws a Ruby exception when attempting to switch to mruby.

Whatever the underlying error is, it causes chruby-fish to exit non-zero, which prevents chruby from switching to mruby at all. This has been reported separately to chruby-fish as a related issue.

Steps To Reproduce

Steps to reproduce the bug:

  1. ruby-install mruby-3.0.0
  2. exec bash, which is required for chruby to pick up the newly installed Ruby
  3. chruby mruby; echo or chruby mruby-3.0.0

Expected Behavior

chruby should either exit non-zero if there's an error during the switch, or not display an error if the Ruby exception raised is expected.

Actual Behavior

My default Ruby is currently set to Ruby 3.1.2. ruby-install mruby-3.0.0 succeeds without error. Under Bash, the following error occurs:

$ chruby mruby
trace (most recent call last):
-:1: undefined method 'defined?' (NoMethodError)

$ echo $?
0

The current Ruby is still changed to mruby-3.0.0, RUBY_ROOT is set correctly, and mirb is executable.

Environment

$ bash --version | head -1
GNU bash, version 5.1.16(1)-release (x86_64-apple-darwin20.6.0)

$ chruby --version
chruby: 0.3.9

$ ruby --version
mruby 3.0.0 (2021-03-05)

$ gem --version
4.0.3

$ gem env | sed "s/$(id -un)/\$LOGNAME/g"
RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.3
  - RUBY VERSION: 2.6.3 (2019-04-16 patchlevel 62) [universal.x86_64-darwin20]
  - INSTALLATION DIRECTORY: /Users/$LOGNAME/.gem
  - USER INSTALLATION DIRECTORY: /Users/$LOGNAME/.gem/ruby/2.6.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
  - GIT EXECUTABLE: /usr/local/bin/git
  - EXECUTABLE DIRECTORY: /Users/$LOGNAME/.gem/bin
  - SPEC CACHE DIRECTORY: /Users/$LOGNAME/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-20
  - GEM PATHS:
     - /Users/$LOGNAME/.gem
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["https://rubygems.org"]
     - :concurrent_downloads => 4
     - "gem" => "--env-shebang --minimal-deps --no-document --patch --suggestions --wrappers"
  - REMOTE SOURCES:
     - https://rubygems.org
  - SHELL PATH:
     - /Users/$LOGNAME/.gem///bin
     - /Users/$LOGNAME/.rubies/mruby-3.0.0/bin
     - /usr/local/opt/python@3.9/libexec/bin
     - /Users/$LOGNAME/bin
     - /Users/$LOGNAME/perl5/bin
     - /usr/local/bin
     - /usr/local/sbin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /opt/puppetlabs/pdk/bin
     - /opt/X11/bin
     - /opt/puppetlabs/bin
     - /Library/Apple/usr/bin
     - /Users/$LOGNAME/bin
     - /Users/$LOGNAME/perl5/bin
     - /usr/local/sbin
     - /usr/local/opt/openssl/bin
     - /usr/local/Cellar/python@3.9/3.9.12/libexec/bin
     - /usr/local/opt/openssl@1.1/bin
     - /usr/local/opt/openssl@3/bin
     - /Users/$LOGNAME/.local/bin/jetbrains
     - /usr/local/opt/v8@3.15/bin
     - /usr/local/opt/gcc/bin
     - /Users/$LOGNAME/node_modules/bin
     - /Users/$LOGNAME/go/bin
@postmodern
Copy link
Owner

Ah, this was fixed by c44c6cc, which probably should get a patch release. The other bug is that chruby_use is not checking$? before executing the output of the ruby command. Something like this should catch it:

local ruby_env="$(RUBYGEMS_GEMDEPS="" "$RUBY_ROOT/bin/ruby" - <<EOF
puts "export RUBY_ENGINE=#{Object.const_defined?(:RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'};"
puts "export RUBY_VERSION=#{RUBY_VERSION};"
begin; require 'rubygems'; puts "export GEM_ROOT=#{Gem.default_dir.inspect};"; rescue LoadError; end
EOF)"

if (( $? != 0 )); then
  echo "chruby: failed to execute $1/bin/ruby command" >&2
  return -1
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants