From d4aa7c0b562e90b3a761a117bec44bffb19075f0 Mon Sep 17 00:00:00 2001 From: Randell Dawson Date: Thu, 22 Nov 2018 23:40:32 -0800 Subject: [PATCH] fix: added catch for unexpected frontmatter error --- .../guide-folder-checks/frontmatter-check.js | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/validation/guide-folder-checks/frontmatter-check.js b/validation/guide-folder-checks/frontmatter-check.js index e344991c6b..8e7c4ca737 100644 --- a/validation/guide-folder-checks/frontmatter-check.js +++ b/validation/guide-folder-checks/frontmatter-check.js @@ -1,22 +1,31 @@ const matter = require('gray-matter'); const _ = require('lodash'); -const dedent = require('dedent'); const frontmatterCheck = (fullPath, isTranslation, fileContent) => { - const { data: frontmatter } = matter(fileContent); let errors = []; - if (!frontmatter || _.isEmpty(frontmatter) || !frontmatter.title) { + try { + const { data: frontmatter } = matter(fileContent); + if (!frontmatter || _.isEmpty(frontmatter) || !frontmatter.title) { + errors.push({ + msg: `Misplaced or missing \`title\` keyword in the front matter block. Review the [style guide](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md#title) for more details.`, + fullPath + }); + } + if (isTranslation && !frontmatter.localeTitle) { + errors.push({ + msg: `Missing \`localeTitle\` keyword in the front matter block. Review the [style guide](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md#title) for more details.`, + fullPath + }); + } + } + catch(err) { errors.push({ - msg: `Misplaced or missing \`title\` keyword in the front matter block. Review the [style guide](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md#title) for more details.`, - fullPath - }); - } - if (isTranslation && !frontmatter.localeTitle) { - errors.push({ - msg: `Missing \`localeTitle\` keyword in the front matter block. Review the [style guide](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md#title) for more details.`, + msg: `Unexpected syntax found in the front matter block. Review Travis CI build Details link above for more details.`, fullPath }); } + + return errors; };