Rubocop: Ruby 2.6.0-preview2 does not support new Psych.safe_load interface.

Created on 27 Oct 2018  ·  6Comments  ·  Source: rubocop-hq/rubocop

:wave: Hey folks! I wanted to flag an issue I noticed with #6396. It implements a new interface for Psych.safe_load that's landed in Ruby trunk, checking that the active Ruby version is at least 2.6. Unfortunately, the last 2.6 preview passes the version check but does not include the new Psych code; running Rubocop under Ruby 2.6.0-preview2 yields an error like this:

/usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/2.6.0/psych.rb:313:in `safe_load': unknown keywords: whitelist_classes, whitelist_symbols, aliases, filename (ArgumentError)
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/rubocop-0.60.0/lib/rubocop/config_loader.rb:185:in `yaml_safe_load'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/rubocop-0.60.0/lib/rubocop/config_loader.rb:159:in `load_yaml_configuration'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/rubocop-rspec-1.30.0/lib/rubocop/rspec/inject.rb:8:in `defaults!'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/rubocop-rspec-1.30.0/lib/rubocop-rspec.rb:24:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/gems/2.6.0/gems/bundler-1.17.1/lib/bundler/runtime.rb:81:in `require'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/gems/2.6.0/gems/bundler-1.17.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/gems/2.6.0/gems/bundler-1.17.1/lib/bundler/runtime.rb:76:in `each'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/gems/2.6.0/gems/bundler-1.17.1/lib/bundler/runtime.rb:76:in `block in require'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/gems/2.6.0/gems/bundler-1.17.1/lib/bundler/runtime.rb:65:in `each'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/gems/2.6.0/gems/bundler-1.17.1/lib/bundler/runtime.rb:65:in `require'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/gems/2.6.0/gems/bundler-1.17.1/lib/bundler.rb:114:in `require'
    from /Users/daniel/Repos/Ignota/structur-api/config/application.rb:21:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /usr/local/rvm/gems/ruby-2.6.0-preview2@structur/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/rvm/rubies/ruby-2.6.0-preview2/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

I've just installed ruby-head for the time being, so this is a pretty low-pressure complaint, but I imagine it's not uncommon for folks to be using the preview rather than a trunk build. Maybe the version check could be stricter?

Thanks for looking into it, and for all your work maintaining Rubocop!


Expected behavior

Rubocop should load successfully under Ruby 2.6.0-preview2.

Actual behavior

Rubocop crashes with an error about the keyword arguments passed to Psych.safe_load.

Steps to reproduce the problem

  1. Install Ruby 2.6.0-preview2.
  2. Attempt to run Rubocop with a custom config file.
  3. :boom:

RuboCop version

~ ❯❯❯ rubocop -V
0.60.0 (using Parser 2.5.1.2, running on ruby 2.6.0 x86_64-darwin18)
bug

Most helpful comment

Any idea when a new version of rubocop gem will be released? Thanks....

All 6 comments

Also seeing this for 11 of my repos after upgrading to rubocop 0.60.0 gem:

ArgumentError: unknown keywords: whitelist_classes, whitelist_symbols, aliases, filename
/Users/.../.rvm/gems/[email protected]/gems/rubocop-0.60.0/lib/rubocop/config_loader.rb:185:in `yaml_safe_load'
/Users/.../.rvm/gems/[email protected]/gems/rubocop-0.60.0/lib/rubocop/config_loader.rb:159:in `load_yaml_configuration'

Thanks for the feedback. I opened a PR #6413 that fixed this issue.

Neat, thanks for the speedy response!

Any idea when a new version of rubocop gem will be released? Thanks....

Note: I found that docker's official ruby image v2.6rc uses older bundler and rubygems. and caused this problem.

unknown keywords: permitted_classes, permitted_symbols
/usr/local/lib/ruby/2.6.0/psych.rb:328:in `safe_load'
/home/circleci/project/vendor/bundle/ruby/2.6.0/gems/rubocop-0.61.0/lib/rubocop/config_loader.rb:188:in `yaml_safe_load'
/home/circleci/project/vendor/bundle/ruby/2.6.0/gems/rubocop-0.61.0/lib/rubocop/config_loader.rb:161:in `load_yaml_configuration'

$ gem -version
warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, whitelist_classes: ...) instead.
warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, whitelist_classes: ...) instead.
ERROR:  Invalid option: -version. See 'gem --help'.
$ gem -v
warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, whitelist_classes: ...) instead.
warning: Passing whitelist_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, whitelist_classes: ...) instead.
2.7.8
$ bundler -v
Bundler version 1.17.1
$ ruby -v
ruby 2.6.0preview3 (2018-11-06 trunk 65578) [x86_64-linux]

It may be fixed after https://github.com/docker-library/ruby/pull/251 merged

@walf443 - Thanks for the update.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

david942j picture david942j  ·  3Comments

mikegee picture mikegee  ·  3Comments

bquorning picture bquorning  ·  3Comments

lepieru picture lepieru  ·  3Comments

tedPen picture tedPen  ·  3Comments