Unverified Commit 1dcf9816 authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

Don't log suppressed error during export (#45100)

Checks if we're exporting and skips to log the suppressed errors.

Before

![image](https://user-images.githubusercontent.com/25056922/213746411-c1834b65-ebf5-4db5-91b7-e77c9707d78a.png)

After

![image](https://user-images.githubusercontent.com/25056922/213746255-04322f83-68b6-4271-b4fb-c363bd2a8c9d.png)

Fixes NEXT-399

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/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`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 440560fb
......@@ -184,6 +184,7 @@ export type RenderOptsPartial = {
isBot?: boolean
incrementalCache?: import('./lib/incremental-cache').IncrementalCache
isRevalidate?: boolean
nextExport?: boolean
}
export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
......@@ -214,6 +215,7 @@ function createErrorHandler(
* Used for debugging
*/
_source: string,
isNextExport: boolean,
capturedErrors: Error[],
allCapturedErrors?: Error[]
) {
......@@ -236,7 +238,19 @@ function createErrorHandler(
}
// Used for debugging error source
// console.error(_source, err)
console.error(err)
// Don't log the suppressed error during export
if (
!(
isNextExport &&
err?.message?.includes(
'The specific message is omitted in production builds to avoid leaking sensitive details.'
)
)
) {
console.error(err)
}
capturedErrors.push(err)
// TODO-APP: look at using webcrypto instead. Requires a promise to be awaited.
return stringHash(err.message + err.stack + (err.digest || '')).toString()
......@@ -882,16 +896,20 @@ export async function renderToHTMLOrFlight(
const capturedErrors: Error[] = []
const allCapturedErrors: Error[] = []
const isNextExport = !!renderOpts.nextExport
const serverComponentsErrorHandler = createErrorHandler(
'serverComponentsRenderer',
isNextExport,
capturedErrors
)
const flightDataRendererErrorHandler = createErrorHandler(
'flightDataRenderer',
isNextExport,
capturedErrors
)
const htmlRendererErrorHandler = createErrorHandler(
'htmlRenderer',
isNextExport,
capturedErrors,
allCapturedErrors
)
......
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
throw new Error('Page build time error')
}
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { join } from 'path'
describe('app-dir-hide-suppressed-error-during-next-export', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
skipStart: true,
files: {
'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
app: new FileRef(join(__dirname, 'app')),
},
})
})
afterAll(() => next.destroy())
it('should not log suppressed error when exporting static page', async () => {
await expect(next.start()).rejects.toThrow('next build failed')
expect(next.cliOutput).toInclude('Page build time error')
expect(next.cliOutput).toInclude('occurred prerendering page "/"')
expect(next.cliOutput).toInclude(
'Export encountered errors on following paths'
)
expect(next.cliOutput).not.toInclude(
'The specific message is omitted in production builds to avoid leaking sensitive details.'
)
})
})
/** @type {import("next").NextConfig} */
const nextConfig = {
experimental: { appDir: true },
}
module.exports = nextConfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment