diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-04-17 10:20:16 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-04-17 10:20:38 +0200 |
commit | 159bed34c3a850d58d08a36ddc40372ed96af2db (patch) | |
tree | e793dec52797fb30fd97ccc8e259296a9bde2902 | |
parent | 5cc944ffd77289ab0b8efd69d628fb11d1280993 (diff) |
parser: Add some context to front matter parse error
Fixes #4638
-rw-r--r-- | parser/page.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/parser/page.go b/parser/page.go index 17378840d..84a59f186 100644 --- a/parser/page.go +++ b/parser/page.go @@ -308,7 +308,7 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e // pre-reads beginning delimiter length - 1 bytes from Reader for i := 0; i < len(left)-1; i++ { if c, err = r.ReadByte(); err != nil { - return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s", buf.Len(), err) + return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s\n%.100s...", buf.Len(), err, buf.String()) } if err = buf.WriteByte(c); err != nil { return nil, err @@ -323,7 +323,7 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e // is expected that the delimiter only contains one character. for { if c, err = r.ReadByte(); err != nil { - return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s", buf.Len(), err) + return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s\n%.100s...", buf.Len(), err, buf.String()) } if err = buf.WriteByte(c); err != nil { return nil, err @@ -344,7 +344,7 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e if err != nil { // It is ok that the end delimiter ends with EOF if err != io.EOF || level != 1 { - return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s", buf.Len(), err) + return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s\n%.100s...", buf.Len(), err, buf.String()) } } else { switch c { @@ -358,7 +358,7 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e return nil, err } if c, err = r.ReadByte(); err != nil { - return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s", buf.Len(), err) + return nil, fmt.Errorf("unable to read frontmatter at filepos %d: %s\n%.100s...", buf.Len(), err, buf.String()) } if c != '\n' { return nil, fmt.Errorf("frontmatter delimiter must be followed by CR+LF or LF but those can't be found at filepos %d", buf.Len()) |