rails error, couldn't parse YAML

2019-01-02 14:32发布

After updating the gems I've got this:

/home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 182 column 9 (Psych::SyntaxError)
    from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
    from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:119:in `parse'
    from /home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:106:in `load'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth/formatters/latex.rb:6:in `<module:LATEX>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth/formatters/latex.rb:3:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth.rb:21:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/redcloth.rb:21:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/case_sensitive_require/RedCloth.rb:6:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/RedCloth-4.2.3/lib/case_sensitive_require/RedCloth.rb:6:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `block in require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.10/lib/bundler.rb:120:in `require'
    from /home/megas/Work/railscasts/config/application.rb:10:in `<top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
    from /home/megas/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

ruby-1.9.2-p136 rails 3.0.3

Tried to reinstall gem RedCloth, didn't help, system wants to use only 4.2.3 version

Any idea how to fix it? Thanks

29条回答
后来的你喜欢了谁
2楼-- · 2019-01-02 15:01

It's a bundler 1.0.10 issue: details here

Try just to downdate bundler

查看更多
高级女魔头
3楼-- · 2019-01-02 15:02

I manage to fix this problem by installing gem psych inside group :development and :test.

gem 'psych'
查看更多
像晚风撩人
4楼-- · 2019-01-02 15:03

Well, just in case this helps...
What I did:
- select all and copy from https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/es.yml into a new es.yml with notepad++
- tried to watch this new file with netBeans IDE text editor, I got a warning about safe load with utf8 (cannot recall the exact text). Hence did not open it with this text editor.
- switched the local thru configuration/application.rb i18n
- when I loaded a irb page I got "couldn't parse YAML at line 0 column 0" referring to Psych.
- Went to IRB and loaded the file with syck it was ok; switched to psych and got same error.

How I solved it:
- went back to copy the contents from https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/es.yml but this time I pasted it in a newly created file with netBeans editor.
- restarted webRick.
- problem solved.
Best Regards,
Victor

查看更多
时光乱了年华
5楼-- · 2019-01-02 15:05

Absolutely fix your yaml code don't just 'mask' the real problem by forcing YAMl to use 'syck'. I had this same problem and found malformed yml statements in my localization files. If you just force using the older parser then you will not get the benefits of all the work on the new parser elsewhere in your project.

查看更多
无与为乐者.
6楼-- · 2019-01-02 15:05

Though the answer given by @Vicvega may or may not work (Didn't test it) it goes against Rails and Ruby common principle "Convention over configuration" and should be treated with care (and even more in collaborative work),,, even though the "configuration" in this case is not great

so my vote goes (If i could vote) for those who proposed to eliminate the syntax errors in the YAML files.

now... to solve the error, for me it was kind of a newby error, I didn't have the locale file which I had defined to be the default in Config/application.rb in my Config/locales directory

happy coding

查看更多
梦寄多情
7楼-- · 2019-01-02 15:05

I got this error from trying to connect to a remote db with the password 'p@ssword' and figured out that psych doesn't like the '@' symbol. Changed the DB password and problem solved.

查看更多
登录 后发表回答