Truffleruby: Cannot `require 'rouge'` in RC15: Coercion error: nil.to_str => String failed

Created on 12 Apr 2019  路  10Comments  路  Source: oracle/truffleruby

I used to be able to load rouge in RC12:

GraalVM MultiLanguage Shell 1.0.0-rc12
Copyright (c) 2013-2019, Oracle and/or its affiliates
  JavaScript version 1.0
  Ruby version 2.4.4
ruby> require 'rouge'
true
ruby>

It no longer works in RC15:

GraalVM MultiLanguage Shell 1.0.0-rc15
Copyright (c) 2013-2019, Oracle and/or its affiliates
  JavaScript version 1.0
  Ruby version 2.6.2
ruby> require 'rouge'
Coercion error: nil.to_str => String failed (TypeError)
        at <ruby> <top (required)>(<shell>:1:0-14)
        at <ruby> null(Unknown)
ruby>

In both cases, I have used gem install rouge which installed rouge-3.3.0.

bug polyglot

All 10 comments

Same error occurs when I try to require "nokogiri", not sure what is causing this issue yet.

Thank you for the report.

Which command are you using the the shell?
bin/polyglot --jvm --shell ?

Yes. Everything seems to work fine with bin/truffleruby.

Launching with --ruby.debug gives a bit more information:

$ bin/polyglot --jvm --shell --experimental-options --ruby.debug                       
GraalVM MultiLanguage Shell 1.0.0-rc15
Copyright (c) 2013-2019, Oracle and/or its affiliates
  JavaScript version 1.0
  Ruby version 2.6.2
Usage: 
  Use Ctrl+L to switch language and Ctrl+D to exit.
  Enter -usage to get a list of available commands.
ruby> require "rouge"
Exception `LoadError' at <shell>:1:in `require' - cannot load such file -- rouge
Exception `Errno::ENOENT' at /home/eregon/code/graalvm-ce-1.0.0-rc15/jre/languages/ruby/lib/mri/rubygems/util.rb:125:in `errno_error' - No such file or directory
Exception: `Errno::ENOENT' /home/eregon/code/graalvm-ce-1.0.0-rc15/jre/languages/ruby/lib/mri/rubygems/util.rb:125:in `handle' - No such file or directory
Exception `LoadError' at /home/eregon/code/graalvm-ce-1.0.0-rc15/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:54:in `require' - cannot load such file -- rouge
Exception `Errno::ENOENT' at /home/eregon/code/graalvm-ce-1.0.0-rc15/jre/languages/ruby/lib/mri/rubygems/util.rb:125:in `errno_error' - No such file or directory
Exception: `Errno::ENOENT' /home/eregon/code/graalvm-ce-1.0.0-rc15/jre/languages/ruby/lib/mri/rubygems/util.rb:125:in `handle' - No such file or directory
Exception `NoMethodError' at /home/eregon/code/graalvm-ce-1.0.0-rc15/jre/languages/ruby/lib/mri/rubygems/bundler_version_finder.rb:51:in `execute_coerce_to' - undefined method `to_str' for nil:NilClass
Exception: `TypeError' /home/eregon/code/graalvm-ce-1.0.0-rc15/jre/languages/ruby/lib/mri/rubygems/bundler_version_finder.rb:51:in `coerce_to_failed' - Coercion error: nil.to_str => String failed
Coercion error: nil.to_str => String failed (TypeError)
        at <ruby> <top (required)>(<shell>:1:0-14)
        at <ruby> null(Unknown)

Not sure it helps, but this is what it looks like on GraalVM RC12 EE:

GraalVM MultiLanguage Shell 1.0.0-rc12
Copyright (c) 2013-2019, Oracle and/or its affiliates
  Ruby version 2.4.4
js> ruby>
ruby> require "rouge"
Exception `LoadError' at <shell>:1:in `gem_original_require' - cannot load such file -- rouge
Exception `LoadError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require' - cannot load such file -- rouge
Exception `LoadError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:55:in `gem_original_require' - cannot load such file -- cgi/escape
Exception: `LoadError' bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/rubygems/core_ext/kernel_require.rb:135:in `require' - cannot load such file -- cgi/escape
Exception `NameError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/psych/class_loader.rb:68:in `const_missing' - uninitialized constant Date
Exception `NameError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/psych/class_loader.rb:68:in `const_missing' - uninitialized constant BigDecimal
Exception `NameError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/psych/class_loader.rb:68:in `const_missing' - uninitialized constant DateTime
Exception `NameError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/psych/core_ext.rb:17:in `remove_method' - method `to_yaml' not defined in Object
Exception `NameError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/psych/core_ext.rb:30:in `remove_method' - method `yaml_as' not defined in Module
Exception `NameError' at bin/graalvm-ee-1.0.0-rc12/Contents/Home/jre/languages/ruby/lib/mri/psych/deprecated.rb:82:in `Object' - undefined method `to_yaml_properties' for Object
true

That line in rubygems/bundler_version_finder.rb:51 is:

  def self.bundle_update_bundler_version
    return unless File.basename($0) == "bundle".freeze

And $0 is nil because it's currently only set if run from a RubyLauncher (bin/ruby).
What changed is we updated to Ruby 2.6, with a newer version of RubyGems.

Great, thanks for the info! I was able to find a workaround and now I can require nokogiri and rouge again. I'll leave the proper bug fixing to you ;)

Setting $0 manually is a workaround (note that it will also change the process title):

$ bin/polyglot --jvm --shell                                                                 
GraalVM MultiLanguage Shell 1.0.0-rc15
Copyright (c) 2013-2019, Oracle and/or its affiliates
  JavaScript version 1.0
  Ruby version 2.6.2
Usage: 
  Use Ctrl+L to switch language and Ctrl+D to exit.
  Enter -usage to get a list of available commands.
ruby> $0 = "polyglot-shell"
"polyglot-shell"
ruby> require 'rouge'
true

The bug fix is likely to initialize $0 to e.g. - or -e which MRI uses when the input script is stdin or -e respectively. The RubyLauncher would then just override that value since it has more information.

Ideally, it should also be set to the filename (test.rb) in this case:

$ bin/polyglot --jvm test.rb

Sorry for the slow update, but this was fixed in 5989bf5a9326a3715475b4c6d358123ae05c0c5a and will be available in the next release.

Was this page helpful?
0 / 5 - 0 ratings