Skip to content

Commit

Permalink
[gatsby] Report an error when layout file is missing (#3762)
Browse files Browse the repository at this point in the history
* [gatsby] Report an error when layout file is missing

* Update pages-writer.js

* format
  • Loading branch information
szimek authored and KyleAMathews committed Jan 29, 2018
1 parent bb8f0f3 commit 128f0d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 10 additions & 3 deletions packages/gatsby/src/internal-plugins/query-runner/pages-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -133,8 +142,6 @@ const preferDefault = m => m && m.default || m
asyncRequires
),
])

return
}

exports.writePages = writePages
Expand Down

0 comments on commit 128f0d1

Please sign in to comment.