From 128f0d1bb6c141512fd94d63b890caa375c22253 Mon Sep 17 00:00:00 2001 From: Szymon Nowak Date: Mon, 29 Jan 2018 19:15:08 +0100 Subject: [PATCH] [gatsby] Report an error when layout file is missing (#3762) * [gatsby] Report an error when layout file is missing * Update pages-writer.js * format --- packages/gatsby/src/bootstrap/index.js | 6 +++++- .../internal-plugins/query-runner/pages-writer.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/src/bootstrap/index.js b/packages/gatsby/src/bootstrap/index.js index e57f841b691e1..a5e16b401a349 100644 --- a/packages/gatsby/src/bootstrap/index.js +++ b/packages/gatsby/src/bootstrap/index.js @@ -357,7 +357,11 @@ module.exports = async (args: BootstrapArgs) => { // Write out files. activity = report.activityTimer(`write out page data`) activity.start() - await writePages() + try { + await writePages() + } catch (err) { + report.panic(`Failed to write out page data`, err) + } activity.end() // Write out redirects. diff --git a/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js b/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js index f11ac7f746095..b74bc04797344 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js +++ b/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js @@ -43,6 +43,15 @@ const writePages = async () => { }) if (p.layout) { let layout = getLayoutById(layouts)(p.layout) + + if (!layout) { + throw new Error( + `Could not find layout '${ + p.layout + }'. Check if this file exists in 'src/layouts'.` + ) + } + pageLayouts.push(layout) json.push({ jsonName: layout.jsonName, @@ -122,7 +131,7 @@ const preferDefault = m => m && m.default || m .join(`,\n`)} }` - await Promise.all([ + return await Promise.all([ fs.writeFile( joinPath(program.directory, `.cache/pages.json`), JSON.stringify(pagesData, null, 4) @@ -133,8 +142,6 @@ const preferDefault = m => m && m.default || m asyncRequires ), ]) - - return } exports.writePages = writePages