palkan/anyway_config

Psych 4: safe_load by default, Ruby 3.1 - Unknown alias: default

sampokuokkanen opened this issue · 1 comments

What did you do?

A rather basic newly created Rails app with --main flag, so reports itself as 7.1.0.alpha.
Seems to happen even if I downgrade to Rails 7.0.

If I try to start AnyCable with bundle exec anycable, I get the following error:

Unknown alias: default

The error seems to come from Anyway Config, so creating an issue here.
Seems to happen because of Psych 4.
Related information:
https://www.redmine.org/issues/36226

What did you expect to happen?

I expected AnyCable to start.

The basic AnyCable config uses a default setting, which is not recognized.

If I change:

# anyway_config-2.2.2/lib/anyway/loaders/yaml.rb
# line 32
if defined?(ERB)
  ::YAML.safe_load(ERB.new(File.read(path)).result) || {} # rubocop:disable Security/YAMLLoad
else
...

to using unsafe load, the config works fine. Also if I remove the default block and just copy & paste the settings everything also works fine.

What actually happened?

I get the following error:

Unknown alias: default
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:430:in `visit_Psych_Nodes_Alias'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each_slice'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `revive_hash'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each_slice'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `revive_hash'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:318:in `visit_Psych_Nodes_Document'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych.rb:335:in `safe_load'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych.rb:370:in `load'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/anyway_config-2.2.2/lib/anyway/loaders/yaml.rb:33:in `parse_yml'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/anyway_config-2.2.2/lib/anyway/rails/loaders/yaml.rb:8:in `load_base_yml'
/home/sampo/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/anyway_config-2.2.2/lib/anyway/loaders/yaml.rb:13:in `block in call'

Additional context

Environment

Development

Ruby Version:

3.1.0

Framework Version (Rails, whatever):

Rails from main branch, 7.1.0.alpha

Anyway Config Version:
2.2.2

Sorry, somehow didn't notice then open PR for this!