From b5b2bdf29313677c9acaa286cd323c7639295eb9 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 2 Dec 2021 13:31:36 -0600 Subject: [PATCH] Include page for export errors for easier debugging (#32013) This makes sure to include the `page` for dynamic routes when they encounter an error during prerendering as we currently only include the `path`, e.g. before we would only show `/blog/first` and now we show `/blog/[slug]: /blog/first` ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` --- packages/next/export/index.ts | 5 ++++- .../auto-export-query-error/test/index.test.js | 1 - .../handles-export-errors/pages/blog/[slug].js | 16 ++++++++++++++++ .../handles-export-errors/test/index.test.js | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/integration/handles-export-errors/pages/blog/[slug].js diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index 3c25978233460..4fdd1c8b04dfc 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -600,7 +600,10 @@ export default async function exportApp( ampValidationResult.errors.length > 0) } renderError = renderError || !!result.error - if (!!result.error) errorPaths.push(path) + if (!!result.error) { + const { page } = pathMap + errorPaths.push(page !== path ? `${page}: ${path}` : path) + } if (options.buildExport && configuration) { if (typeof result.fromBuildExportRevalidate !== 'undefined') { diff --git a/test/integration/auto-export-query-error/test/index.test.js b/test/integration/auto-export-query-error/test/index.test.js index d33210ca90587..d0589b58b22bf 100644 --- a/test/integration/auto-export-query-error/test/index.test.js +++ b/test/integration/auto-export-query-error/test/index.test.js @@ -20,7 +20,6 @@ const runTests = () => { expect(stderr).not.toContain('/amp') expect(stderr).not.toContain('/ssr') expect(stderr).not.toContain('/ssg') - expect(stderr).not.toContain('/hello') }) } diff --git a/test/integration/handles-export-errors/pages/blog/[slug].js b/test/integration/handles-export-errors/pages/blog/[slug].js new file mode 100644 index 0000000000000..fe9b6bab7da8e --- /dev/null +++ b/test/integration/handles-export-errors/pages/blog/[slug].js @@ -0,0 +1,16 @@ +export default function Page() { + throw new Error('oops') +} + +export function getStaticProps() { + return { + props: {}, + } +} + +export function getStaticPaths() { + return { + paths: ['/blog/first', '/blog/second'], + fallback: false, + } +} diff --git a/test/integration/handles-export-errors/test/index.test.js b/test/integration/handles-export-errors/test/index.test.js index 1e07907e4a491..6ac3736e9b1f6 100644 --- a/test/integration/handles-export-errors/test/index.test.js +++ b/test/integration/handles-export-errors/test/index.test.js @@ -19,5 +19,7 @@ describe('Handles Errors During Export', () => { expect(stderr).toContain('/page-2') expect(stderr).toContain('/page-3') expect(stderr).toContain('/page-13') + expect(stderr).toContain('/blog/[slug]: /blog/first') + expect(stderr).toContain('/blog/[slug]: /blog/second') }) })