Unverified Commit d94e8db5 authored by Christian Stuff's avatar Christian Stuff Committed by GitHub

Add failing paths to export error summary (#10026)

Closes #9990 by collecting all paths with errors during `next export` and reporting them sorted in the error summary at the end.

It will produce an output similar to:

```
    Error: Export encountered errors on following paths:
        /nested/page
        /page
        /page-1
        /page-10
        /page-11
        /page-12
        /page-13
        /page-2
        /page-3
        /page-4
        /page-5
        /page-6
        /page-7
        /page-8
        /page-9
        at _default (/app/next.js/packages/next/dist/export/index.js:19:788)
        at process._tickCallback (internal/process/next_tick.js:68:7)
```

I tested the output with the `handle-export-errors` integration test suite, but I'm not sure how to gracefully test this added output.
I thought of collecting all page source files with [recursiveReaddirSync](https://github.com/zeit/next.js/blob/2ba352da39ee00b6595aecdc9ffb2f103e803a85/packages/next/next-server/server/lib/recursive-readdir-sync.ts) but it seems I can't import it in js test files:

```
SyntaxError: /app/next.js/packages/next/next-server/server/lib/recursive-readdir-sync.ts: Unexpected token, expected "," (11:5)

       9 |  */
      10 | export function recursiveReadDirSync(
    > 11 |   dir: string,
         |      ^
      12 |   arr: string[] = [],
      13 |   rootDir = dir
      14 | ): string[] {
```

The test itself could look like:
```js
  it('Reports failing paths', async () => {
    const { stderr } = await nextBuild(appDir, [], {
      stdout: true,
      stderr: true,
    })
    const pages = []
    // collect pages to be ['/page', '/page-1', ... etc.]
    pages.forEach(page => {
      expect(stderr).toContain(page)
    })
  })
```
parent fafa16f3
...@@ -368,6 +368,7 @@ export default async function exportApp( ...@@ -368,6 +368,7 @@ export default async function exportApp(
worker.getStderr().pipe(process.stderr) worker.getStderr().pipe(process.stderr)
let renderError = false let renderError = false
const errorPaths: string[] = []
await Promise.all( await Promise.all(
filteredPaths.map(async (path) => { filteredPaths.map(async (path) => {
...@@ -393,6 +394,7 @@ export default async function exportApp( ...@@ -393,6 +394,7 @@ export default async function exportApp(
(Array.isArray(result?.errors) && result.errors.length > 0) (Array.isArray(result?.errors) && result.errors.length > 0)
} }
renderError = renderError || !!result.error renderError = renderError || !!result.error
if (!!result.error) errorPaths.push(path)
if ( if (
options.buildExport && options.buildExport &&
...@@ -448,7 +450,11 @@ export default async function exportApp( ...@@ -448,7 +450,11 @@ export default async function exportApp(
} }
if (renderError) { if (renderError) {
throw new Error(`Export encountered errors`) throw new Error(
`Export encountered errors on following paths:\n\t${errorPaths
.sort()
.join('\n\t')}`
)
} }
// Add an empty line to the console for the better readability. // Add an empty line to the console for the better readability.
log('') log('')
......
...@@ -14,5 +14,11 @@ describe('Handles Errors During Export', () => { ...@@ -14,5 +14,11 @@ describe('Handles Errors During Export', () => {
}) })
expect(stdout + stderr).not.toMatch(/ERR_IPC_CHANNEL_CLOSED/) expect(stdout + stderr).not.toMatch(/ERR_IPC_CHANNEL_CLOSED/)
expect(stderr).toContain('Export encountered errors on following paths')
expect(stderr).toContain('/page')
expect(stderr).toContain('/page-1')
expect(stderr).toContain('/page-2')
expect(stderr).toContain('/page-3')
expect(stderr).toContain('/page-13')
}) })
}) })
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