laserlemon / figaro

Simple Rails app configuration
MIT License
3.77k stars 287 forks source link

`visit_Psych_Nodes_Alias': Unknown alias: shared (Psych::BadAlias) error with ruby 3.1 #289

Open Alexander-Andrade opened 1 year ago

Alexander-Andrade commented 1 year ago

When trying to run rails c, or rails s after migration from ruby 3.0.0 to ruby 3.1.2 got this

/home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:430:in `visit_Psych_Nodes_Alias': Unknown alias: shared (Psych::BadAlias)
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each_slice'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `revive_hash'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each_slice'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `revive_hash'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:318:in `visit_Psych_Nodes_Document'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych.rb:335:in `safe_load'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/3.1.0/psych.rb:370:in `load'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:60:in `parse'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:56:in `block in raw_configuration'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:56:in `raw_configuration'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:64:in `global_configuration'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:32:in `configuration'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:42:in `each'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:36:in `load'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro.rb:23:in `load'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/rails/railtie.rb:5:in `block in <class:Railtie>'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.3/lib/active_support/lazy_load_hooks.rb:68:in `block in execute_hook'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.3/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.3/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.3/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.3/lib/active_support/lazy_load_hooks.rb:51:in `each'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.3/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/lib/rails/application.rb:74:in `inherited'
    from /home/burbulis/Documents/projects/ruby/Boatyard-OMS/config/application.rb:24:in `<module:Boatyard>'
    from /home/burbulis/Documents/projects/ruby/Boatyard-OMS/config/application.rb:22:in `<main>'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/lib/rails/command/actions.rb:22:in `require_application!'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/lib/rails/command/actions.rb:14:in `require_application_and_environment!'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/lib/rails/commands/console/console_command.rb:101:in `perform'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/lib/rails/command/base.rb:87:in `perform'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/lib/rails/command.rb:48:in `invoke'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/railties-7.0.2.3/lib/rails/commands.rb:18:in `<main>'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from bin/rails:4:in `<main>'

Seems the problem is in /home/burbulis/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/figaro-1.2.0/lib/figaro/application.rb:59

    def parse(path)
      File.exist?(path) && YAML.load(ERB.new(File.read(path)).result) || {}
    end

YAML.load has the next value "# ------------------------------------------------------------------------------\n# App configuration through environment variables\n# ------------------------------------------------------------------------------\n# Copy this template to config/application.yml and adjust as needed\n#\n# - Please ONLY use this file to add values that CANNOT be configured as:\n# Encrypted credentials\n# Configuration through Rails.application.config_for\n#\n# - Please add a clear description for each variable\n#\n# - Please keep this template and your local copy synchronized with actual variables\n# in the corresponding environment\n# ------------------------------------------------------------------------------\n\n# Values shared for all environments\nshared: &shared\n\ndevelopment:\n <<: shared\n # Set to false to enable OneSignal notifications to be sent in development\n DISABLE_ONE_SIGNAL: false\n\nstaging:\n <<: shared\n\nproduction:\n <<: *shared\n"

Loschcode commented 1 year ago

I have the same problem. It doesn't seem addressed at all by this gem and Ruby 3.1 was released almost a year ago.

scarroll32 commented 1 year ago

Anyone have a fix for this?

hlascelles commented 1 year ago

I have decided to fork this gem, so that its inspiration may live again. The new gem is called figjam.

It can be found here: https://github.com/hlascelles/figjam

It is a drop-in replacement (sans heroku) for Figaro (with Figjam module aliasing to Figaro too)

I will apply this PR to it, unless you want to open the same PR there. I will attribute this author,