Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -946,5 +946,6 @@
"945": "createNodeStreamFromChunks cannot be used in the edge runtime",
"946": "Failed to deserialize errors.",
"947": "Expected `sendErrorsToBrowser` to be defined in renderOpts.",
"948": "Failed to serialize errors."
"948": "Failed to serialize errors.",
"949": "Route %s errored during %s. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled.\n \nOriginal Error: %s"
}
53 changes: 44 additions & 9 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ import {
createReactServerPrerenderResultFromRender,
prerenderAndAbortInSequentialTasks,
} from './app-render-prerender-utils'
import { printDebugThrownValueForProspectiveRender } from './prospective-render-utils'
import {
Phase,
printDebugThrownValueForProspectiveRender,
} from './prospective-render-utils'
import {
pipelineInSequentialTasks,
scheduleInSequentialTasks,
Expand Down Expand Up @@ -1073,7 +1076,11 @@ async function prospectiveRuntimeServerPrerender(
process.env.NEXT_DEBUG_BUILD ||
process.env.__NEXT_VERBOSE_LOGGING
) {
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
},
// We don't want to stop rendering until the cacheSignal is complete so we pass
Expand Down Expand Up @@ -1110,7 +1117,11 @@ async function prospectiveRuntimeServerPrerender(
) {
// We don't normally log these errors because we are going to retry anyway but
// it can be useful for debugging Next.js itself to get visibility here when needed
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
return null
}
Expand Down Expand Up @@ -3832,7 +3843,11 @@ async function warmupModuleCacheForRuntimeValidationInDev(
) {
// We don't normally log these errors because we are going to retry anyway but
// it can be useful for debugging Next.js itself to get visibility here when needed
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
},
// We don't need bootstrap scripts in this prerender
Expand Down Expand Up @@ -3863,7 +3878,11 @@ async function warmupModuleCacheForRuntimeValidationInDev(
) {
// We don't normally log these errors because we are going to retry anyway but
// it can be useful for debugging Next.js itself to get visibility here when needed
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
})

Expand Down Expand Up @@ -4350,7 +4369,11 @@ async function prerenderToStream(
process.env.NEXT_DEBUG_BUILD ||
process.env.__NEXT_VERBOSE_LOGGING
) {
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
},
// We don't want to stop rendering until the cacheSignal is complete so we pass
Expand Down Expand Up @@ -4402,7 +4425,11 @@ async function prerenderToStream(
) {
// We don't normally log these errors because we are going to retry anyway but
// it can be useful for debugging Next.js itself to get visibility here when needed
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
}

Expand Down Expand Up @@ -4473,7 +4500,11 @@ async function prerenderToStream(
) {
// We don't normally log these errors because we are going to retry anyway but
// it can be useful for debugging Next.js itself to get visibility here when needed
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
},
bootstrapScripts: [bootstrapScript],
Expand Down Expand Up @@ -4503,7 +4534,11 @@ async function prerenderToStream(
) {
// We don't normally log these errors because we are going to retry anyway but
// it can be useful for debugging Next.js itself to get visibility here when needed
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
})

Expand Down
13 changes: 13 additions & 0 deletions packages/next/src/server/app-render/collect-segment-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import {
HEAD_REQUEST_KEY,
} from '../../shared/lib/segment-cache/segment-value-encoding'
import { getDigestForWellKnownError } from './create-error-handler'
import {
Phase,
printDebugThrownValueForProspectiveRender,
} from './prospective-render-utils'
import { workAsyncStorage } from './work-async-storage.external'

// Contains metadata about the route tree. The client must fetch this before
// it can fetch any actual segment data.
Expand Down Expand Up @@ -85,6 +90,14 @@ function onSegmentPrerenderError(error: unknown) {
}
// We don't need to log the errors because we would have already done that
// when generating the original Flight stream for the whole page.
if (process.env.NEXT_DEBUG_BUILD || process.env.__NEXT_VERBOSE_LOGGING) {
const workStore = workAsyncStorage.getStore()
printDebugThrownValueForProspectiveRender(
error,
workStore?.route ?? 'unknown route',
Phase.SegmentCollection
)
}
}

export async function collectSegmentData(
Expand Down
14 changes: 10 additions & 4 deletions packages/next/src/server/app-render/prospective-render-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { getDigestForWellKnownError } from './create-error-handler'
import { isReactLargeShellError } from './react-large-shell-error'

export enum Phase {
ProspectiveRender = 'the prospective render',
SegmentCollection = 'segment collection',
}

export function printDebugThrownValueForProspectiveRender(
thrownValue: unknown,
route: string
route: string,
phase: Phase
) {
// We don't need to print well-known Next.js errors.
if (getDigestForWellKnownError(thrownValue)) {
Expand All @@ -28,7 +34,7 @@ export function printDebugThrownValueForProspectiveRender(
const stackStart = originalErrorStack.indexOf('\n')
if (stackStart > -1) {
const error = new Error(
`Route ${route} errored during the prospective render. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled.
`Route ${route} errored during ${phase}. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled.

Original Error: ${message}`
)
Expand All @@ -43,14 +49,14 @@ Original Error: ${message}`
}

if (message) {
console.error(`Route ${route} errored during the prospective render. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled. No stack was provided.
console.error(`Route ${route} errored during ${phase}. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled. No stack was provided.

Original Message: ${message}`)
return
}

console.error(
`Route ${route} errored during the prospective render. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled. The thrown value is logged just following this message`
`Route ${route} errored during ${phase}. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled. The thrown value is logged just following this message`
)
console.error(thrownValue)
return
Expand Down
14 changes: 11 additions & 3 deletions packages/next/src/server/route-modules/app-route/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import {
import { HeadersAdapter } from '../../web/spec-extension/adapters/headers'
import { RequestCookiesAdapter } from '../../web/spec-extension/adapters/request-cookies'
import { parsedUrlQueryToParams } from './helpers/parsed-url-query-to-params'
import { printDebugThrownValueForProspectiveRender } from '../../app-render/prospective-render-utils'
import {
Phase,
printDebugThrownValueForProspectiveRender,
} from '../../app-render/prospective-render-utils'

import * as serverHooks from '../../../client/components/hooks-server-context'
import { DynamicServerError } from '../../../client/components/hooks-server-context'
Expand Down Expand Up @@ -432,7 +435,11 @@ export class AppRouteRouteModule extends RouteModule<
process.env.NEXT_DEBUG_BUILD ||
process.env.__NEXT_VERBOSE_LOGGING
) {
printDebugThrownValueForProspectiveRender(err, workStore.route)
printDebugThrownValueForProspectiveRender(
err,
workStore.route,
Phase.ProspectiveRender
)
}
}
if (
Expand All @@ -452,7 +459,8 @@ export class AppRouteRouteModule extends RouteModule<
} else if (process.env.NEXT_DEBUG_BUILD) {
printDebugThrownValueForProspectiveRender(
err,
workStore.route
workStore.route,
Phase.ProspectiveRender
)
}
}
Expand Down
Loading