Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown alias when loading any yaml file

When I try to load any yaml file in my app, I get this error:

Psych::BadAlias: Unknown alias: default
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:385:in `visit_Psych_Nodes_Alias'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:15:in `visit'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:5:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:31:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:321:in `block in revive_hash'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `each'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `each_slice'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `revive_hash'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:161:in `visit_Psych_Nodes_Mapping'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:15:in `visit'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:5:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:31:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:321:in `block in revive_hash'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `each'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `each_slice'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:319:in `revive_hash'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:161:in `visit_Psych_Nodes_Mapping'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:15:in `visit'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:5:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:31:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:295:in `visit_Psych_Nodes_Document'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:15:in `visit'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/visitor.rb:5:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych/visitors/to_ruby.rb:31:in `accept'
  /Users/luizkowalski/.rbenv/versions/2.2.3/lib/ruby/2.2.0/psych.rb:295:in `safe_load'
  /Users/luizkowalski/rails_dev/api/app/services/country_products_limitations_policy.rb:3:in `<class:CountryProductsLimitationsPolicy>'

I'm updating a Rails app from 4.1 to 4.2.8 using Ruby 2.2.3.

The yaml file is this one:

default: &default
  no_yearly_plans:
    - TH
    - SD
    - PK
    - SA
    - BH
    - SY
    - IQ
    - QA
    - YE
    - BY
    - OM
    - JO
    - CI
    - KW
    - AE

production:
  <<: *default

staging:
  <<: *default

development:
  <<: *default

test:
  <<: *default

My first assumption was that this file was wrong, but all linters says it is fine, so I don't know what could be

like image 242
Luiz E. Avatar asked Apr 18 '17 09:04

Luiz E.


1 Answers

If you use safe_load you need to explicitly enable aliases:

YAML.safe_load path_to_yaml, [], [], true
like image 188
aromero Avatar answered Nov 08 '22 03:11

aromero