better error message if the YAML is not well-formatted + do not try to load YAML from an empty string
did
committed Sep 11, 2015
commit 2c9f36bb8c296e9dd62c64203f348796cd968a5d
Showing 1
changed file with
13 additions
and 3 deletions
locomotive/steam/adapters/filesystem/yaml_loader.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
+13
-3
| @@ | @@ -27,15 +27,25 @@ module Locomotive::Steam |
| yaml, template = match[:yaml], match[:template] | |
| end | |
| - | HashConverter.to_sym(YAML.load(yaml)).tap do |attributes| |
| - | block.call(attributes, template) if block_given? |
| - | end |
| + | safe_yaml_load(yaml, template, path, &block) |
| else | |
| Locomotive::Common::Logger.error "No #{path} file found" | |
| {} | |
| end | |
| end | |
| + | def safe_yaml_load(yaml, template, path, &block) |
| + | return {} if yaml.blank? |
| + | |
| + | begin |
| + | HashConverter.to_sym(YAML.load(yaml)).tap do |attributes| |
| + | block.call(attributes, template) if block_given? |
| + | end |
| + | rescue Exception => e |
| + | raise "Malformed YAML in this file #{path}, error: #{e.message}" |
| + | end |
| + | end |
| + | |
| def template_extensions | |
| @extensions ||= %w(liquid haml) | |
| end | |