Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix error with wrong encoding or error in YAML #498

Closed
wants to merge 2 commits into from

5 participants

@stereobooster

before

/psych.rb:148:in `parse': couldn't parse YAML at line 9 column 0 (Psych::SyntaxError)
        from /psych.rb:148:in `parse_stream'
        from /psych.rb:119:in `parse'
        from /psych.rb:106:in `load'
        from /lib/jekyll/convertible.rb:33:in `read_yaml'
        from /lib/jekyll/post.rb:41:in `initialize'
        from /lib/jekyll/site.rb:166:in `new'
        from /lib/jekyll/site.rb:166:in `block in read_posts'
        from /lib/jekyll/site.rb:164:in `each'
        from /lib/jekyll/site.rb:164:in `read_posts'
        from /lib/jekyll/site.rb:131:in `read_directories'
        from /lib/jekyll/site.rb:101:in `read'
        from /lib/jekyll/site.rb:39:in `process'
        from /bin/jekyll:254:in `<top (required)>'
        from /bin/jekyll:19:in `load'
        from /bin/jekyll:19:in `<main>'

after

YAML Exception reading 2012-01-02-microformats.html: couldn't parse YAML at line 9 column 0
@stereobooster

connected with #188, fix #248

@stereobooster
rescue => e

is synonym to

rescue StandardError => e

But psych raise Psych::SyntaxError which is subclass of ::SyntaxError

Exception
  ScriptError
    SyntaxError
  StandardError

This is clearly a small bug. Can this small fix be merged?

@stereobooster

@svnpenn did error message became clearer? That is what my patch about.

@svnpenn

No, this one

convertible.rb:26:in `read_yaml': invalid byte sequence in UTF-8 (ArgumentError)
@stereobooster

To fix this, you need to change (in convertible.rb)

    def read_yaml(base, name)
      self.content = File.read(File.join(base, name))

      begin
        if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m

to

    def read_yaml(base, name)
      begin
        self.content = File.read(File.join(base, name))
        if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m

Didn't test it. But it should be it.

@gerardc

Any updates on this request? It seems like a solid fix

@parkr
Owner

Biiiiiiiiig ups. :+1:

@parkr
Owner

@stereobooster, can you commit these to a patch/feature branch and re-submit? Going master-to-master is usually not the best plan ever.

@parkr parkr referenced this pull request
Closed

YAML Error Messages #248

@parkr
Owner

Please rebase on the current master and re-submit from a feature branch, not master. Re-submit the PR and I'll bring it to @mojombo's attention.

@parkr parkr closed this
@parkr
Owner

(I've made note of this PR in case you don't re-submit, @stereobooster, as these changes are desired.)

@stereobooster

I will resubmit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 2 deletions.
  1. +5 −2 lib/jekyll/convertible.rb
View
7 lib/jekyll/convertible.rb
@@ -25,17 +25,20 @@ def to_s
#
# Returns nothing.
def read_yaml(base, name)
- self.content = File.read(File.join(base, name))
-
begin
+ self.content = File.read(File.join(base, name))
+
if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
self.content = $POSTMATCH
self.data = YAML.load($1)
end
rescue => e
+ puts "Error reading file #{name}: #{e.message}"
+ rescue SyntaxError => e
puts "YAML Exception reading #{name}: #{e.message}"
end
+ self.content ||= ""
self.data ||= {}
end
Something went wrong with that request. Please try again.