Skip to content

Commit

Permalink
Include page for export errors for easier debugging (#32013)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
ijjk authored and Kikobeats committed Dec 3, 2021
1 parent a490ae4 commit b5b2bdf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
}

Expand Down
16 changes: 16 additions & 0 deletions test/integration/handles-export-errors/pages/blog/[slug].js
Original file line number Diff line number Diff line change
@@ -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,
}
}
2 changes: 2 additions & 0 deletions test/integration/handles-export-errors/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit b5b2bdf

Please sign in to comment.