Gatsby: Handle errors in frontmatter

Created on 17 Feb 2018  Â·  4Comments  Â·  Source: gatsbyjs/gatsby

Description

Maybe I'm doing something wrong, but it seems gatsby doesn't warn/error on syntax errors in frontmatter sections.

Environment

Gatsby version: 1.9.166

Actual result

Pages with syntax errors in frontmatter section get siliently ignored.

Expected behavior

Gatsby should error out or at least warn about this.

help wanted needs more info

Most helpful comment

screen shot 2018-05-16 at 9 08 31 pm


Full output

error Plugin gatsby-transformer-remark returned an error

YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key at line 7, column 1:
^

  • loader.js:165 generateError
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:165:10

  • loader.js:171 throwError
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:171:9

  • loader.js:1046 readBlockMapping
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1046:9

  • loader.js:1332 composeNode
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1332:12

  • loader.js:1492 readDocument
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1492:3

  • loader.js:1548 loadDocuments
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1548:5

  • loader.js:1569 load
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1569:19

  • loader.js:1591 Object.safeLoad
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1591:10

  • parse.js:12 module.exports
    [literally.fyi]/[gray-matter]/lib/parse.js:12:17

  • index.js:94 parseMatter
    [literally.fyi]/[gray-matter]/index.js:94:15

  • index.js:46 matter
    [literally.fyi]/[gray-matter]/index.js:46:10

  • on-node-create.js:49 Object._callee$
    [literally.fyi]/[gatsby-transformer-remark]/on-node-create.js:49:20

  • next_tick.js:150 process._tickCallback
    internal/process/next_tick.js:150:11


This is the existing behavior (surfacing the error from within gray-matter) and it feels adequate to me, but how do you feel about it @discordianfish? Can you provide steps to reproduce the situation where a syntax error doesn't result in a logged error like this?

All 4 comments

This is where we parse the markdown files and their frontmatter https://github.com/gatsbyjs/gatsby/blob/77794d2916c927316b3c3ae55a0d4c1d8de88e3e/packages/gatsby-transformer-remark/src/on-node-create.js#L20

Could you investigate if graymatter does expose errors and if so, make a PR sending those to the console?

screen shot 2018-05-16 at 9 08 31 pm


Full output

error Plugin gatsby-transformer-remark returned an error

YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key at line 7, column 1:
^

  • loader.js:165 generateError
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:165:10

  • loader.js:171 throwError
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:171:9

  • loader.js:1046 readBlockMapping
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1046:9

  • loader.js:1332 composeNode
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1332:12

  • loader.js:1492 readDocument
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1492:3

  • loader.js:1548 loadDocuments
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1548:5

  • loader.js:1569 load
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1569:19

  • loader.js:1591 Object.safeLoad
    [literally.fyi]/[js-yaml]/lib/js-yaml/loader.js:1591:10

  • parse.js:12 module.exports
    [literally.fyi]/[gray-matter]/lib/parse.js:12:17

  • index.js:94 parseMatter
    [literally.fyi]/[gray-matter]/index.js:94:15

  • index.js:46 matter
    [literally.fyi]/[gray-matter]/index.js:46:10

  • on-node-create.js:49 Object._callee$
    [literally.fyi]/[gatsby-transformer-remark]/on-node-create.js:49:20

  • next_tick.js:150 process._tickCallback
    internal/process/next_tick.js:150:11


This is the existing behavior (surfacing the error from within gray-matter) and it feels adequate to me, but how do you feel about it @discordianfish? Can you provide steps to reproduce the situation where a syntax error doesn't result in a logged error like this?

@flipactual Oh that's awesome! I think this is totally sufficient. Bonus points though for showing the line(s) what couldn't be parsed. But great either way!

@discordianfish to be clear – I didn't do anything 😄 This is what happened when I tried to reproduce the problem, so maybe it's been fixed along the way somehow

Feel encouraged to reopen if you see the issue again, and we'll dig back in!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timbrandin picture timbrandin  Â·  3Comments

hobochild picture hobochild  Â·  3Comments

kalinchernev picture kalinchernev  Â·  3Comments

dustinhorton picture dustinhorton  Â·  3Comments

ferMartz picture ferMartz  Â·  3Comments