Skip to content

Commit

Permalink
Check stack property for page export exceptions (#32289)
Browse files Browse the repository at this point in the history
Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
benmerckx and ijjk committed Dec 16, 2021
1 parent c87204e commit 04fbc66
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/export/worker.ts
Expand Up @@ -503,7 +503,7 @@ export default async function exportPage({
} catch (error) {
console.error(
`\nError occurred prerendering page "${path}". Read more: https://nextjs.org/docs/messages/prerender-error\n` +
(isError(error) ? error.stack : error)
(isError(error) && error.stack ? error.stack : error)
)
results.error = true
}
Expand Down
13 changes: 13 additions & 0 deletions test/integration/handles-export-errors/pages/custom-error.js
@@ -0,0 +1,13 @@
class CustomError {
constructor(message, data) {
this.message = message
this.data = data
}
toString() {
return this.message
}
}

export default () => {
throw new CustomError('custom error message', {})
}
2 changes: 2 additions & 0 deletions test/integration/handles-export-errors/test/index.test.js
Expand Up @@ -21,5 +21,7 @@ describe('Handles Errors During Export', () => {
expect(stderr).toContain('/page-13')
expect(stderr).toContain('/blog/[slug]: /blog/first')
expect(stderr).toContain('/blog/[slug]: /blog/second')
expect(stderr).toContain('/custom-error')
expect(stderr).toContain('custom error message')
})
})

0 comments on commit 04fbc66

Please sign in to comment.