From f002576a3c24f824a5eb122a044e10067da41b0e Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Tue, 14 Mar 2023 09:57:24 -0400 Subject: [PATCH] [Take 2] Throw error if children entry can't be found, even if early access (#35523) --- lib/create-tree.js | 20 +++++++++++--------- server.js | 6 +++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/create-tree.js b/lib/create-tree.js index 2bdab9a95c..aaea8fd1b8 100644 --- a/lib/create-tree.js +++ b/lib/create-tree.js @@ -30,14 +30,19 @@ export default async function createTree(originalPath, rootPath, previousTree) { try { mtime = await getMtime(filepath) } catch (error) { - if (error.code === 'ENOENT' && filepath.split(path.sep).includes('early-access')) { - // Do not throw an error if Early Access is not available. - console.warn( - `${filepath} could not be turned into a Page, but is ignored because it's early-access` - ) + if (error.code !== 'ENOENT') { + throw error + } + // Throw an error if we can't find a content file associated with the children: entry. + // But don't throw an error if the user is running the site locally and hasn't cloned the Early Access repo. + if (originalPath === path.join('content', 'early-access')) { return } - throw error + throw new Error( + `Cannot find a content file at ${originalPath}. Fix the children frontmatter entry "/${path.basename( + originalPath + )}" in ${path.dirname(originalPath)}/index.md.\n` + ) } } @@ -114,9 +119,6 @@ export default async function createTree(originalPath, rootPath, previousTree) { // (early exit instead of returning a tree). So let's // mutate the `page.children` so we can benefit from the // ability to reload the site tree on consective requests. - if (child !== 'early-access') { - console.warn(`Remove '${child}' from ${item.page.children}`) - } item.page.children = item.page.children.filter((c) => c !== child) } return subTree diff --git a/server.js b/server.js index a48da58794..30354d42c8 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,7 @@ import { main } from './start-server.js' -main() +try { + await main() +} catch (error) { + console.error(error) +}