Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

psych doesn't handle exceptions gracefully (empty hashes in this case) #114

Closed
robmathews opened this Issue Jan 8, 2013 · 0 comments

Comments

2 participants

If you have a config.yml that has a blank defaults in it, like so:

# Be sure to restart your server when you modify this file.
defaults: &defaults

development:
  <<: *defaults
  drupal_host: https://www.goodmeasures.com

It generates an ugly stack trace that doesn't mention which file it is parsing or what line number the error is on. This makes it hard to debug and find the offending file. The stack trace looks something like see ugly traceback in the gist

One easy fix would be to change lib/psych.rb#load_file and add a rescue, something like this:

def self.load_file filename
  File.open(filename, 'r:bom|utf-8') { |f| self.load f, filename }
rescue
  puts "psych: Trouble parsing #{filename}"
end

which at least gets you the filename, if not the actual line number.

Of course a more complete fix would also address allowing the blank hashes, but that would be OK if at least psych told me which configuration file of hundreds to look in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment