Skip to content

Commit f002576

Browse files
authored
[Take 2] Throw error if children entry can't be found, even if early access (github#35523)
1 parent ee25e81 commit f002576

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/create-tree.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ export default async function createTree(originalPath, rootPath, previousTree) {
3030
try {
3131
mtime = await getMtime(filepath)
3232
} catch (error) {
33-
if (error.code === 'ENOENT' && filepath.split(path.sep).includes('early-access')) {
34-
// Do not throw an error if Early Access is not available.
35-
console.warn(
36-
`${filepath} could not be turned into a Page, but is ignored because it's early-access`
37-
)
33+
if (error.code !== 'ENOENT') {
34+
throw error
35+
}
36+
// Throw an error if we can't find a content file associated with the children: entry.
37+
// But don't throw an error if the user is running the site locally and hasn't cloned the Early Access repo.
38+
if (originalPath === path.join('content', 'early-access')) {
3839
return
3940
}
40-
throw error
41+
throw new Error(
42+
`Cannot find a content file at ${originalPath}. Fix the children frontmatter entry "/${path.basename(
43+
originalPath
44+
)}" in ${path.dirname(originalPath)}/index.md.\n`
45+
)
4146
}
4247
}
4348

@@ -114,9 +119,6 @@ export default async function createTree(originalPath, rootPath, previousTree) {
114119
// (early exit instead of returning a tree). So let's
115120
// mutate the `page.children` so we can benefit from the
116121
// ability to reload the site tree on consective requests.
117-
if (child !== 'early-access') {
118-
console.warn(`Remove '${child}' from ${item.page.children}`)
119-
}
120122
item.page.children = item.page.children.filter((c) => c !== child)
121123
}
122124
return subTree

server.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import { main } from './start-server.js'
22

3-
main()
3+
try {
4+
await main()
5+
} catch (error) {
6+
console.error(error)
7+
}

0 commit comments

Comments
 (0)