Skip to content

Commit

Permalink
remove circular ExportError import from SSG worker (vercel#68858)
Browse files Browse the repository at this point in the history
These are technically different kinds of errors and results in the
worker importing everything in `build`, which was an unintentional side
effect of vercel#68546.
  • Loading branch information
ztanner committed Aug 13, 2024
1 parent fe7ff3f commit f63f012
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
} from '../build/turborepo-access-trace'
import type { Params } from '../client/components/params'
import { needsExperimentalReact } from '../lib/needs-experimental-react'
import { ExportError } from '.'

const envConfig = require('../shared/lib/runtime-config.external')

Expand All @@ -55,6 +54,10 @@ class TimeoutError extends Error {
code = 'NEXT_EXPORT_TIMEOUT_ERROR'
}

class ExportPageError extends Error {
code = 'NEXT_EXPORT_PAGE_ERROR'
}

async function exportPageImpl(
input: ExportPageInput,
fileWriter: FileWriter
Expand Down Expand Up @@ -396,15 +399,15 @@ export async function exportPages(
// If there was an error in the export, throw it immediately. In the catch block, we might retry the export,
// or immediately fail the build, depending on user configuration. We might also continue on and attempt other pages.
if (result && 'error' in result) {
throw new ExportError()
throw new ExportPageError()
}

// If the export succeeds, break out of the retry loop
break
} catch (err) {
// The only error that should be caught here is an ExportError, as `exportPage` doesn't throw and instead returns an object with an `error` property.
// This is an overly cautious check to ensure that we don't accidentally catch an unexpected error.
if (!(err instanceof ExportError || err instanceof TimeoutError)) {
if (!(err instanceof ExportPageError || err instanceof TimeoutError)) {
throw err
}

Expand All @@ -424,7 +427,7 @@ export async function exportPages(
}
// If prerenderEarlyExit is enabled, we'll exit the build immediately.
if (nextConfig.experimental.prerenderEarlyExit) {
throw new ExportError(
throw new ExportPageError(
`Export encountered an error on ${pageKey}, exiting the build.`
)
} else {
Expand Down

0 comments on commit f63f012

Please sign in to comment.