Fun with Syck and Psych on Heroku
This is one of those posts that's inspired by a desire never to have to investigate the same bug again.
I just deployed an app to Heroku that needs to read its data from a local YAML file in order to function. It runs fine on my Mac, but fails with this message on Heroku:
ActionView::Template::Error (undefined method `downcase' for #<Syck::PrivateType:0x000000043df398>)
Ouch. I was supposed to be calling
downcase on a string. The YAML file on Heroku is identical to the one that I'm using on my Mac, so what's going on?
Thanks to Alessandro Di Maria, I spotted that Heroku's Cedar stack is still using Sych to parse YAML, rather than the newer Psych. You can investigate what you're running like this:
$ rails console Loading development environment (Rails 3.2.5) irb(main):001:0> YAML::ENGINE::yamler => "psych" $ heroku run console Connecting to database specified by DATABASE_URL Loading production environment (Rails 3.2.5) irb(main):001:0> YAML::ENGINE::yamler => "syck"
Feck. Rails 3 will use Psych by default if it can find it. Psych will be enabled automatically if you compile Ruby with
libyaml installed, but (luckily) you can also add
psych to your
Gemfile to force it.
$ echo "gem 'psych' >> Gemfile" && bundle
Problem solved. Cheers Alessandro!
I love feedback and questions -- please say hello on Twitter or leave a comment.