Skip to content

Commit

Permalink
Rescue from Psych::SyntaxError instead of SyntaxError after parsing Y…
Browse files Browse the repository at this point in the history
…AML (jekyll#5828)

Merge pull request 5828
  • Loading branch information
jmhooper authored and jekyllbot committed Nov 22, 2017
1 parent f6cf8b9 commit 1c469eb
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/jekyll/convertible.rb
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ def read_yaml(base, name, opts = {})
self.content = $POSTMATCH
self.data = SafeYAML.load(Regexp.last_match(1))
end
rescue SyntaxError => e
rescue Psych::SyntaxError => e
Jekyll.logger.warn "YAML Exception reading #{filename}: #{e.message}"
raise e if self.site.config["strict_front_matter"]
rescue StandardError => e
4 changes: 2 additions & 2 deletions lib/jekyll/document.rb
Original file line number Diff line number Diff line change
@@ -266,7 +266,7 @@ def read(opts = {})
merge_defaults
read_content(opts)
read_post_data
rescue SyntaxError, StandardError, Errors::FatalException => e
rescue StandardError => e
handle_read_error(e)
end
end
@@ -463,7 +463,7 @@ def read_post_data

private
def handle_read_error(error)
if error.is_a? SyntaxError
if error.is_a? Psych::SyntaxError
Jekyll.logger.error "Error:", "YAML Exception reading #{path}: #{error.message}"
else
Jekyll.logger.error "Error:", "could not read file #{path}: #{error.message}"
2 changes: 1 addition & 1 deletion test/test_convertible.rb
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ class TestConvertible < JekyllUnitTest
ret = @convertible.read_yaml(@base, name)
assert_equal({}, ret)
end
assert_match(%r!YAML Exception|syntax error|Error reading file!, out)
assert_match(%r!YAML Exception!, out)
assert_match(%r!#{File.join(@base, name)}!, out)
end

0 comments on commit 1c469eb

Please sign in to comment.