Skip to content

Commit

Permalink
chore: add extra error info for rsc info helper (#54609)
Browse files Browse the repository at this point in the history
When I was working on #54199 , if the file path is wrong the next app build error only shows "can't read file from ...", it took me hours to figure out where it actually fails in next build command. Adding an prefix for the error message so that could identify it easier.

Also clean up other unused comments and incorrect named variables
  • Loading branch information
huozhi committed Aug 26, 2023
1 parent eca06a5 commit 6d401c1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/next/src/build/analysis/get-page-static-info.ts
Expand Up @@ -286,8 +286,9 @@ async function tryToReadFile(filePath: string, shouldThrow: boolean) {
return await fs.readFile(filePath, {
encoding: 'utf8',
})
} catch (error) {
} catch (error: any) {
if (shouldThrow) {
error.message = `Next.js ERROR: Failed to read file ${filePath}:\n${error.message}`
throw error
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/build/index.ts
Expand Up @@ -2865,7 +2865,6 @@ export default async function build(

// If there's /not-found inside app, we prefer it over the pages 404
if (hasStaticApp404) {
// await moveExportedPage('/_error', '/404', '/404', false, 'html')
await moveExportedAppNotFoundTo404()
} else {
// Only move /404 to /404 when there is no custom 404 as in that case we don't know about the 404 page
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/lib/find-page-file.ts
Expand Up @@ -91,7 +91,7 @@ export function createValidFileMatcher(
pageExtensions
)}$`
)
const leafOnlyNotFoundFileRegex = new RegExp(
const rootNotFoundFileRegex = new RegExp(
`^not-found\\.${getExtensionRegexString(pageExtensions)}$`
)
/** TODO-METADATA: support other metadata routes
Expand Down Expand Up @@ -136,7 +136,7 @@ export function createValidFileMatcher(
return false
}
const rest = filePath.slice(appDirPath.length + 1)
return leafOnlyNotFoundFileRegex.test(rest)
return rootNotFoundFileRegex.test(rest)
}

return {
Expand Down

0 comments on commit 6d401c1

Please sign in to comment.