Skip to content
This repository

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

Closed
robmathews opened this Issue January 08, 2013 · 0 comments

2 participants

rob mathews Aaron Patterson
rob mathews

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.

Aaron Patterson tenderlove closed this issue from a commit January 11, 2013
Aaron Patterson * ext/psych/lib/psych/visitors/to_ruby.rb: merge key values that
  contain something besides a hash should be left in tact.

* test/psych/test_merge_keys.rb: test for change

fixes #114
2025502
Aaron Patterson tenderlove closed this in 2025502 January 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.