How to identify YML parse error - ruby-on-rails

I'm getting the following error when I boot my rails 3.1.3 application:
psych.rb:148:in `parse': couldn't parse YAML at line 28 column 9 (Psych::SyntaxError)
I'm guessing it is related to YML file syntax.
The problem appears when I try running:
YAML.load_file "..."
From another rails 3.1.3 application and YMLs are loaded just fine.

The syntax is covered here: http://en.wikipedia.org/wiki/YAML#Syntax
An online parser, which may help you troubleshoot, is here: http://yaml-online-parser.appspot.com/

Found a solution. If you can't find a YML syntax error in your application locale files the problem might be in some of the locale files of a gem you might be using.
I introduced a breakpoint at base.rb:15 (of rails 3.1.3) and there you can see a list of all locale yml files that will be loaded under variable filenames.
Inspecting each one I finally found a file with a

Related

Ruby on Rails | AirBrake Error

Trying to run a project that was provided by a client.
I have the correct versions of Ruby, Gems, Rails, Bundler, Homebrew etc installed.
When I run rails server I get the following error in terminal.
.rvm/gems/ruby-2.2.2/gems/airbrake-ruby-1.0.4/lib/airbrake-ruby.rb:288:in `call_notifier': the 'default' notifier isn't configured (Airbrake::Error)
After much time spent on Google I couldn't find a fix on this.
Here is a screenshot of the whole terminal error message which I get the feeling these other lines could be related.
It looks like a previous developer may have hardcoded a commit hook in the application, pointing to a file in their local .git folder (and which you don't have).
I'd recommend either asking the developer to provide the missing file, create a dummy file in the same place, or removing that line.

Rails: DEPRECATION WARNING: You didn't set config.secret_key_base

I receive this warning when running my specs. Is there a best practice for generating a secret_key_base, or will any string suffice (with regard to security concerns)?
You propably upgraded to Rails 4 from a 3.x or a previous version.
First generate a random secret key value:
$ bundle exec rake secret
Then take that value and put it in config/initializers/secret_token.rb:
YourApp::Application.config.secret_key_base = 'your-secret'
replacing YourApp with the name of your application.
The reason for this is explained here.
Also see http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml
As of 4.1, you need to use the config/secrets.yml file. This is discussed in http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml .
You simply need to create a secret_token.rb file in the config/initializers directory.
Contents of the file below:
YourAppNameHere::Application.config.secret_key_base = #type the key you generated with rake secret here
then save the file
close your server:
ctrl c
restart it: rails s
You'll now see the basic rails app page you saw in the last chapter (If you're working through Hartl's tutorial)
If you are a total noob like me, remember to put the secret_key_base = 'whatever' inside single quotes. Just a copy and paste without quotes will throw an error :
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.8/lib/act
ive_support/dependencies.rb:223:in `load': C:/Users/Jeff C/documents/rails_proje
cts/first_app/config/initializers/secret_token.rb:1: syntax error, unexpected tI
DENTIFIER, expecting $end (SyntaxError)
Had this same issue when working on a Rails 4 application that was upgraded to Rails 5.
All I had to do was run the command below to generate a secret key:
bundle exec rake secret
And then I added the secret key to the config/secret.yml file:
development:
secret_key_base: 21bc6137d0496a2a11f4459a7c7deb4f782d223d41ee328934b2fe7a405a42ec63eb3829db67f0ec6a759e134ba0bb15dc2d01168b64d83efcf8d42b403ac8bd
That's all.
I hope this helps

How to find mystery YAML error?

While working on some tests, I started getting the following error for all tests.
Psych::SyntaxError: couldn't parse YAML at line 92 column 0
Using this code to run tests:
ruby -Itest ./test/functional/users_controller_test.rb
I couldn't find any YAML errors in the fixtures, so I undid all my changes. According to git, the files are in the same state as when I started. But I keep getting the same error.
How to fix? How to find the file that is causing the problem?
Rails 3.0.7
Ruby 1.9.2p290
Upgrade your Rails to a newer 3.0.x version, and look at this other Stack Overflow question for other hints.
Found it! There was a tab character in two fixtures files.
The strange thing is that the files did not change from before. They used to work fine. I am sure of that because git can tell the difference between a tab and a space. (The files are now modified).
Apparently a gem or some other file got updated with a YAML parser that is more picky...but the strange thing is that I did not update anything.
I guess this is a good reason to run RVM or rbenv (which I am). Too bad it doesn't explain what happened...

Heroku logs show syntax error in syck.rb. How to resolve this?

I'm trying to deploy a Rails 3.2 app to Heroku.
When I migrate the database, the rake is aborted.
Checking the logs I see
/usr/local/lib/ruby/1.9.1/syck.rb:135:in `load': syntax error on line 7, col 11: `' (ArgumentError)
I've tried to track down what's causing this, including disabling all non essential gems, reviewing the app for obvious syntax errors, etc. But no luck.
As this error seems to be generated by a Heroku system file, I'm not sure what to try next.
Has anyone else encountered this? Are there any good references that would help me get to the bottom of this?
Sounds like a syntax error on line 7 of a yml file somewhere.
I assume everything is ok locally, so either that yml file has contents based on environment variables which differ between development and production (and the values in production result in incorrect yaml) or the difference comes from using psych (the new yaml parser) locally but syck on heroku. You can check which parser is being used with YAML::ENGINE.

Ruby on Rails config.secret_token error

I just started learning ruby on rails.
I followed a lot of install examples, but when i ran the example am getting this error
A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb
I search for it but i dont see too much help.
plz help.
Platform: Mac OS X.
The easiest way to generate a new secret token is to run
rake secret
at the command line.
Your token should have been generated automatically by Rails, but you could still use something like:
irb(main):007:0> "#{ActiveSupport::SecureRandom.hex(64)}"
=> "921b00fcfabe0368d70627020f3b4c969cfd9bdc2474f4040c1ae976f687014694beb5d36dfc0c41bac8ebde96a14fceaee228d6e34d8183c5d7cc99d310d4f9"
meaning, you can generate some random string and put it into your config/initializers/secret_token.rb file:
# Be sure to restart your server when you modify this file.
Yourapp::Application.config.secret_token = '921b00fcfabe0368d70627020f3b4c969cfd9bdc2474f4040c1ae976f687014694beb5d36dfc0c41bac8ebde96a14fceaee228d6e34d8183c5d7cc99d310d4f9'
This is an issue with rails version probably. I had this issue when I uninstalled Rails 4 and installed Rails 3. After checking rails -v and seeing that it was indeed Rails 3, I executed rails new myapp. For some reason the configuration file config/initializers/secret_token.rb had the "config.secret_key_base" variable defined, which appears to be how Rails 4 does it. I was able to fix it by changing it to "config.secret_token", which I believe is what Rails 3 uses.
This simple command worked for me :
rvmsudo rake generate_secret_token
Make sure you have this in your environment.rb:
YourApp::Application.initialize!
Ran into this same issue and found out my config/initializers/secret_token.rb file was being ignored by git in my .gitignore file. Check out the config/initializers directory in your git source location and make sure the secret_token.rb file exists. If it doesn't edit your .gitignore file so that git will not ignore the secret_token.rb file and commit your changes (usually hidden - I used these simple commands to display hidden files on a mac http://osxdaily.com/2009/02/25/show-hidden-files-in-os-x/).

Resources