Unverified Commit d726535d authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Stop patching error inspection if source maps are disabled (#93364)

If source maps are disabled, we're most likely running in a prod server
where sourcemapping happens lazily when logs are inspected.
Ignore-listing generated frames would forever hide n_m frames.

It also avoids doing a bunch of work that just won't have any effect.

As a follow-up, I'll experiment with showing all frames during
next-build if all original frames are ignore-listed since that's a
one-shot process. For next-dev, we'll continue showing no frames if
everything is ignore-listed since you have an attached a debugger with
the browser to get a high-fidelity UI to see ignore-listed frames.
Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
parent 299c2f48
import * as module from 'module'
import * as process from 'process'
import { patchErrorInspectNodeJS } from '../patch-error-inspect' import { patchErrorInspectNodeJS } from '../patch-error-inspect'
patchErrorInspectNodeJS(globalThis.Error) const sourceMappingEnabled =
// @ts-expect-error Node.js 22+ only
typeof module.getSourceMapsSupport === 'function'
? // @ts-expect-error Node.js 22+ only
module.getSourceMapsSupport().enabled
: process.env.NODE_OPTIONS?.includes('--enable-source-maps') ||
process.execArgv.includes('--enable-source-maps')
if (sourceMappingEnabled) {
patchErrorInspectNodeJS(globalThis.Error)
} else {
// leave Errors untouched if source maps are disabled.
// We're likely in a prod server where sourcemapping is done lazily when logs
// are inspected so ignore-listing would permanently hide these frames.
}
...@@ -9,19 +9,21 @@ const CONFIG_ERROR = ...@@ -9,19 +9,21 @@ const CONFIG_ERROR =
'Server Actions Size Limit must be a valid number or filesize format larger than 1MB' 'Server Actions Size Limit must be a valid number or filesize format larger than 1MB'
describe('app-dir action size limit invalid config', () => { describe('app-dir action size limit invalid config', () => {
const { next, isNextStart, isNextDeploy, skipped } = nextTestSetup({ const { next, isNextDev, isNextStart, isNextDeploy, skipped } = nextTestSetup(
files: __dirname, {
overrideFiles: process.env.TEST_NODE_MIDDLEWARE files: __dirname,
? { overrideFiles: process.env.TEST_NODE_MIDDLEWARE
'middleware.js': new FileRef(join(__dirname, 'middleware-node.js')), ? {
} 'middleware.js': new FileRef(join(__dirname, 'middleware-node.js')),
: {}, }
skipStart: true, : {},
dependencies: { skipStart: true,
nanoid: '4.0.1', dependencies: {
'server-only': 'latest', nanoid: '4.0.1',
}, 'server-only': 'latest',
}) },
}
)
if (skipped) return if (skipped) return
const logs: string[] = [] const logs: string[] = []
...@@ -123,7 +125,7 @@ describe('app-dir action size limit invalid config', () => { ...@@ -123,7 +125,7 @@ describe('app-dir action size limit invalid config', () => {
) )
) )
expect(logs).not.toContainEqual( expect(logs).not.toContainEqual(
expect.stringContaining('Error: Body exceeded 2mb limit') expect.stringContaining('Body exceeded 2mb limit')
) )
} }
}) })
...@@ -149,7 +151,12 @@ describe('app-dir action size limit invalid config', () => { ...@@ -149,7 +151,12 @@ describe('app-dir action size limit invalid config', () => {
if (!isNextDeploy) { if (!isNextDeploy) {
await retry(() => { await retry(() => {
expect(logs).toContainEqual( expect(logs).toContainEqual(
expect.stringContaining('Error: Body exceeded 2mb limit') expect.stringMatching(
isNextDev
? 'Error: Body exceeded 2mb limit'
: // Minified ApiError class name
/\w+ \[Error\]: Body exceeded 2mb limit/
)
) )
expect(logs).toContainEqual( expect(logs).toContainEqual(
expect.stringContaining( expect.stringContaining(
...@@ -187,7 +194,7 @@ describe('app-dir action size limit invalid config', () => { ...@@ -187,7 +194,7 @@ describe('app-dir action size limit invalid config', () => {
) )
) )
expect(logs).not.toContainEqual( expect(logs).not.toContainEqual(
expect.stringContaining('Error: Body exceeded 2mb limit') expect.stringContaining('Body exceeded 2mb limit')
) )
} }
}) })
...@@ -212,7 +219,7 @@ describe('app-dir action size limit invalid config', () => { ...@@ -212,7 +219,7 @@ describe('app-dir action size limit invalid config', () => {
) )
) )
expect(logs).not.toContainEqual( expect(logs).not.toContainEqual(
expect.stringContaining('Error: Body exceeded 2mb limit') expect.stringContaining('Body exceeded 2mb limit')
) )
} }
}) })
...@@ -238,7 +245,12 @@ describe('app-dir action size limit invalid config', () => { ...@@ -238,7 +245,12 @@ describe('app-dir action size limit invalid config', () => {
if (!isNextDeploy) { if (!isNextDeploy) {
await retry(() => { await retry(() => {
expect(logs).toContainEqual( expect(logs).toContainEqual(
expect.stringContaining('Error: Body exceeded 2mb limit') expect.stringMatching(
isNextDev
? 'Error: Body exceeded 2mb limit'
: // Minified ApiError class name
/\w+ \[Error\]: Body exceeded 2mb limit/
)
) )
expect(logs).toContainEqual( expect(logs).toContainEqual(
expect.stringContaining( expect.stringContaining(
......
...@@ -4,6 +4,12 @@ import { hasErrorToast, retry, waitFor, waitForNoRedbox } from 'next-test-utils' ...@@ -4,6 +4,12 @@ import { hasErrorToast, retry, waitFor, waitForNoRedbox } from 'next-test-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
import escapeStringRegexp from 'escape-string-regexp' import escapeStringRegexp from 'escape-string-regexp'
// In production, handler frames are intentionally printed unsourcemapped
// (the server has no source maps) with install-specific path prefixes that
// we don't want to assert on.
const normalizeCacheHandlerPaths = (output: string): string =>
output.replaceAll(/\([^()\s]*(?=throwing-cache-handler\.js)/g, '(')
// TODO(deploy-test-completion): Re-enable this suite in deploy mode. // TODO(deploy-test-completion): Re-enable this suite in deploy mode.
// It likely asserts local CLI or runtime output that deploy tests do not expose. // It likely asserts local CLI or runtime output that deploy tests do not expose.
// @force-gate !deploy // @force-gate !deploy
...@@ -63,7 +69,9 @@ describe('app-custom-cache-handler-errors - get throws', () => { ...@@ -63,7 +69,9 @@ describe('app-custom-cache-handler-errors - get throws', () => {
// asserting its absence. // asserting its absence.
await waitFor(1000) await waitFor(1000)
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = normalizeCacheHandlerPaths(
stripAnsi(next.cliOutput.slice(outputIndex))
)
const errorBlock = isNextDev const errorBlock = isNextDev
? 'Error: CustomCacheHandler.get failed' + ? 'Error: CustomCacheHandler.get failed' +
...@@ -123,10 +131,14 @@ describe('app-custom-cache-handler-errors - set throws', () => { ...@@ -123,10 +131,14 @@ describe('app-custom-cache-handler-errors - set throws', () => {
'\n at Object.set (throwing-cache-handler.js:50:13)' '\n at Object.set (throwing-cache-handler.js:50:13)'
await retry(async () => { await retry(async () => {
expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain(errorBlock) expect(
normalizeCacheHandlerPaths(stripAnsi(next.cliOutput.slice(outputIndex)))
).toContain(errorBlock)
}) })
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = normalizeCacheHandlerPaths(
stripAnsi(next.cliOutput.slice(outputIndex))
)
expect(cliOutput).not.toContain('unhandledRejection') expect(cliOutput).not.toContain('unhandledRejection')
expect(cliOutput).toIncludeRepeated(escapeStringRegexp(errorBlock), 1) expect(cliOutput).toIncludeRepeated(escapeStringRegexp(errorBlock), 1)
}) })
......
...@@ -302,7 +302,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => { ...@@ -302,7 +302,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => {
- [block] Set \`export const instant = false\` to allow a blocking route - [block] Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook
at useSearchParams (webpack:///<next-src>) at useSearchParams (<next-dist-dir>)
at UseSearchParams (webpack:///app/client-hook-abort-reasons/client.tsx:27:18) at UseSearchParams (webpack:///app/client-hook-abort-reasons/client.tsx:27:18)
at Page (webpack:///app/client-hook-abort-reasons/normal/use-search-params/[id]/page.tsx:8:7) at Page (webpack:///app/client-hook-abort-reasons/normal/use-search-params/[id]/page.tsx:8:7)
54 | // Client components API 54 | // Client components API
...@@ -591,7 +591,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => { ...@@ -591,7 +591,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => {
- [block] Set \`export const instant = false\` to allow a blocking route - [block] Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook
at usePathname (webpack:///<next-src>) at usePathname (<next-dist-dir>)
at UsePathname (webpack:///app/client-hook-abort-reasons/client.tsx:22:14) at UsePathname (webpack:///app/client-hook-abort-reasons/client.tsx:22:14)
at Page (webpack:///app/client-hook-abort-reasons/normal/use-pathname/[id]/page.tsx:7:7) at Page (webpack:///app/client-hook-abort-reasons/normal/use-pathname/[id]/page.tsx:7:7)
111 | // Client components API 111 | // Client components API
...@@ -880,7 +880,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => { ...@@ -880,7 +880,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => {
- [block] Set \`export const instant = false\` to allow a blocking route - [block] Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook
at useParams (webpack:///<next-src>) at useParams (<next-dist-dir>)
at UseParams (webpack:///app/client-hook-abort-reasons/client.tsx:17:12) at UseParams (webpack:///app/client-hook-abort-reasons/client.tsx:17:12)
at Page (webpack:///app/client-hook-abort-reasons/normal/use-params/[id]/page.tsx:8:7) at Page (webpack:///app/client-hook-abort-reasons/normal/use-params/[id]/page.tsx:8:7)
214 | // Client components API 214 | // Client components API
...@@ -1169,7 +1169,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => { ...@@ -1169,7 +1169,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => {
- [block] Set \`export const instant = false\` to allow a blocking route - [block] Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook
at useSelectedLayoutSegments (webpack:///<next-src>) at useSelectedLayoutSegments (<next-dist-dir>)
at UseSelectedLayoutSegments (webpack:///app/client-hook-abort-reasons/client.tsx:37:28) at UseSelectedLayoutSegments (webpack:///app/client-hook-abort-reasons/client.tsx:37:28)
at Page (webpack:///app/client-hook-abort-reasons/normal/use-selected-layout-segments/[id]/page.tsx:7:7) at Page (webpack:///app/client-hook-abort-reasons/normal/use-selected-layout-segments/[id]/page.tsx:7:7)
268 | parallelRouteKey: string = 'children' 268 | parallelRouteKey: string = 'children'
...@@ -1458,7 +1458,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => { ...@@ -1458,7 +1458,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => {
- [block] Set \`export const instant = false\` to allow a blocking route - [block] Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook
at useSelectedLayoutSegment (webpack:///<next-src>) at useSelectedLayoutSegment (<next-dist-dir>)
at UseSelectedLayoutSegment (webpack:///app/client-hook-abort-reasons/client.tsx:32:27) at UseSelectedLayoutSegment (webpack:///app/client-hook-abort-reasons/client.tsx:32:27)
at Page (webpack:///app/client-hook-abort-reasons/normal/use-selected-layout-segment/[id]/page.tsx:8:7) at Page (webpack:///app/client-hook-abort-reasons/normal/use-selected-layout-segment/[id]/page.tsx:8:7)
323 | parallelRouteKey: string = 'children' 323 | parallelRouteKey: string = 'children'
...@@ -2168,7 +2168,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => { ...@@ -2168,7 +2168,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => {
- [block] Set \`export const instant = false\` to allow a blocking route - [block] Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook
at useParams (webpack:///<next-src>) at useParams (<next-dist-dir>)
at UseParams (webpack:///app/client-hook-abort-reasons/client.tsx:17:12) at UseParams (webpack:///app/client-hook-abort-reasons/client.tsx:17:12)
at Page (webpack:///app/client-hook-abort-reasons/sync-io/use-params/[id]/page.tsx:7:7) at Page (webpack:///app/client-hook-abort-reasons/sync-io/use-params/[id]/page.tsx:7:7)
214 | // Client components API 214 | // Client components API
...@@ -2666,7 +2666,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => { ...@@ -2666,7 +2666,7 @@ describe('Cache Components Errors - Client Hook Abort Reasons', () => {
- [block] Set \`export const instant = false\` to allow a blocking route - [block] Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook Learn more: https://nextjs.org/docs/messages/blocking-prerender-client-hook
at useSelectedLayoutSegment (webpack:///<next-src>) at useSelectedLayoutSegment (<next-dist-dir>)
at UseSelectedLayoutSegment (webpack:///app/client-hook-abort-reasons/client.tsx:32:27) at UseSelectedLayoutSegment (webpack:///app/client-hook-abort-reasons/client.tsx:32:27)
at Page (webpack:///app/client-hook-abort-reasons/sync-io/use-selected-layout-segment/[id]/page.tsx:8:7) at Page (webpack:///app/client-hook-abort-reasons/sync-io/use-selected-layout-segment/[id]/page.tsx:8:7)
323 | parallelRouteKey: string = 'children' 323 | parallelRouteKey: string = 'children'
......
...@@ -1453,7 +1453,8 @@ Learn more: https://nextjs.org/docs/messages/blocking-prerender-dynamic` ...@@ -1453,7 +1453,8 @@ Learn more: https://nextjs.org/docs/messages/blocking-prerender-dynamic`
expect(output).toMatchInlineSnapshot(` expect(output).toMatchInlineSnapshot(`
"⨯ Error: Kaputt! "⨯ Error: Kaputt!
at a (<next-dist-dir>) at a (<next-dist-dir>)
at b (<next-dist-dir>) { at b (<next-dist-dir>)
at <next-internal> {
digest: '<error-digest>' digest: '<error-digest>'
}" }"
`) `)
...@@ -1522,7 +1523,8 @@ Learn more: https://nextjs.org/docs/messages/blocking-prerender-dynamic` ...@@ -1522,7 +1523,8 @@ Learn more: https://nextjs.org/docs/messages/blocking-prerender-dynamic`
expect(output).toMatchInlineSnapshot(` expect(output).toMatchInlineSnapshot(`
"⨯ Error: Kaputt! "⨯ Error: Kaputt!
at a (<next-dist-dir>) at a (<next-dist-dir>)
at b (<next-dist-dir>) { at b (<next-dist-dir>)
at <next-internal> {
digest: '<error-digest>' digest: '<error-digest>'
} }
[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] { [Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
......
...@@ -58,6 +58,13 @@ export function getDeterministicOutput( ...@@ -58,6 +58,13 @@ export function getDeterministicOutput(
const replaceNumericModuleId = () => `at ${n++} (` const replaceNumericModuleId = () => `at ${n++} (`
let isErrorWithStackTraceStartingInLibraryInternals = false let isErrorWithStackTraceStartingInLibraryInternals = false
// With the error-inspect patch disabled (no source maps at runtime), errors
// intentionally show the raw framework tail of the stack: frames from the
// compiled Next.js runtime, which we collapse into a single placeholder,
// and Node.js internals, which we drop since they differ across Node.js
// versions.
let isCollapsingFrameworkFrames = false
let frameAnchor: number | null = null
for (let line of cliOutput.split('\n')) { for (let line of cliOutput.split('\n')) {
if ( if (
!isErrorWithStackTraceStartingInLibraryInternals && !isErrorWithStackTraceStartingInLibraryInternals &&
...@@ -100,6 +107,34 @@ export function getDeterministicOutput( ...@@ -100,6 +107,34 @@ export function getDeterministicOutput(
foundStartingLine && foundStartingLine &&
!ignoredLines.some((ignoredLine) => line.includes(ignoredLine)) !ignoredLines.some((ignoredLine) => line.includes(ignoredLine))
) { ) {
if (
!isCollapsingFrameworkFrames &&
/^\s+at .*node_modules\/next\/dist\//.test(line)
) {
isCollapsingFrameworkFrames = !line.endsWith(' {')
lines.push(' at <next-internal>' + (line.endsWith(' {') ? ' {' : ''))
frameAnchor = lines.length - 1
continue
}
if (isCollapsingFrameworkFrames) {
if (line.startsWith(' at ')) {
if (line.endsWith(' {')) {
lines[frameAnchor!] += ' {'
isCollapsingFrameworkFrames = false
}
continue
}
isCollapsingFrameworkFrames = false
}
if (/^\s+at (?:async )?(?:[\w$.]+ )?\(?node:/.test(line)) {
// The ` {` that opens the printed error properties is attached to the
// last frame, so it has to be re-attached to the last kept frame.
if (line.endsWith(' {') && frameAnchor !== null) {
lines[frameAnchor] += ' {'
}
continue
}
if (isMinified) { if (isMinified) {
line = line.replace( line = line.replace(
/at (\S+) \(<anonymous>\)/, /at (\S+) \(<anonymous>\)/,
...@@ -113,7 +148,7 @@ export function getDeterministicOutput( ...@@ -113,7 +148,7 @@ export function getDeterministicOutput(
} }
line = line line = line
.replace(/at (.+?) \(.next[^)]+\)/, replaceNextDistStackFrame) .replace(/at (.+?) \((.*?\/)?.next[^)]+\)/, replaceNextDistStackFrame)
.replace( .replace(
// Single-letter lower-case names are likely minified. // Single-letter lower-case names are likely minified.
/at [a-z] \((?!(<next-dist-dir>|<anonymous>))/, /at [a-z] \((?!(<next-dist-dir>|<anonymous>))/,
...@@ -123,6 +158,7 @@ export function getDeterministicOutput( ...@@ -123,6 +158,7 @@ export function getDeterministicOutput(
.replace(/digest: '\d+(@E\d+)?'/, "digest: '<error-digest>'") .replace(/digest: '\d+(@E\d+)?'/, "digest: '<error-digest>'")
lines.push(convertModuleFunctionSequenceExpression(line)) lines.push(convertModuleFunctionSequenceExpression(line))
frameAnchor = line.startsWith(' at ') ? lines.length - 1 : null
} }
} }
......
...@@ -544,7 +544,7 @@ describe('ensureStatic = "navigation"', () => { ...@@ -544,7 +544,7 @@ describe('ensureStatic = "navigation"', () => {
> Build error occurred > Build error occurred
Error: Failed to collect page data for /default/fallback-params/[slug] Error: Failed to collect page data for /default/fallback-params/[slug]
at ignore-listed frames { at <next-internal> {
type: 'Error' type: 'Error'
}" }"
`) `)
...@@ -585,7 +585,7 @@ describe('ensureStatic = "navigation"', () => { ...@@ -585,7 +585,7 @@ describe('ensureStatic = "navigation"', () => {
> Build error occurred > Build error occurred
Error: Failed to collect page data for /default/fallback-params-passed-to-client/[slug] Error: Failed to collect page data for /default/fallback-params-passed-to-client/[slug]
at ignore-listed frames { at <next-internal> {
type: 'Error' type: 'Error'
}" }"
`) `)
...@@ -623,7 +623,7 @@ describe('ensureStatic = "navigation"', () => { ...@@ -623,7 +623,7 @@ describe('ensureStatic = "navigation"', () => {
> Build error occurred > Build error occurred
Error: Failed to collect page data for /default/fallback-params-client-segment/[slug] Error: Failed to collect page data for /default/fallback-params-client-segment/[slug]
at ignore-listed frames { at <next-internal> {
type: 'Error' type: 'Error'
}" }"
`) `)
...@@ -820,7 +820,7 @@ describe('ensureStatic = "navigation"', () => { ...@@ -820,7 +820,7 @@ describe('ensureStatic = "navigation"', () => {
> Build error occurred > Build error occurred
Error: Failed to collect page data for /default/static-params-empty/[slug] Error: Failed to collect page data for /default/static-params-empty/[slug]
at ignore-listed frames { at <next-internal> {
type: 'Error' type: 'Error'
}" }"
`) `)
...@@ -856,7 +856,7 @@ describe('ensureStatic = "navigation"', () => { ...@@ -856,7 +856,7 @@ describe('ensureStatic = "navigation"', () => {
> Build error occurred > Build error occurred
Error: Failed to collect page data for /default/static-params-incomplete/[slug]/[snail] Error: Failed to collect page data for /default/static-params-incomplete/[slug]/[snail]
at ignore-listed frames { at <next-internal> {
type: 'Error' type: 'Error'
}" }"
`) `)
...@@ -893,7 +893,7 @@ describe('ensureStatic = "navigation"', () => { ...@@ -893,7 +893,7 @@ describe('ensureStatic = "navigation"', () => {
> Build error occurred > Build error occurred
Error: Failed to collect page data for /default/static-params-incomplete-unused/[slug]/[snail] Error: Failed to collect page data for /default/static-params-incomplete-unused/[slug]/[snail]
at ignore-listed frames { at <next-internal> {
type: 'Error' type: 'Error'
}" }"
`) `)
......
...@@ -158,13 +158,10 @@ describe('app-dir - errors', () => { ...@@ -158,13 +158,10 @@ describe('app-dir - errors', () => {
) )
) )
} else { } else {
expect(cleanCliOutput).toMatchInlineSnapshot(` expect(cleanCliOutput).toContain('⨯ Error: undefined')
"⨯ Error: undefined // No runtime sourcemapping so the stack is just a bunch of library internals
at ignore-listed frames { expect(cleanCliOutput).toContain("digest: '<digest>'")
digest: '<digest>' expect(cleanCliOutput).not.toContain('ignore-listed frames')
}
"
`)
} }
}) })
...@@ -196,13 +193,10 @@ describe('app-dir - errors', () => { ...@@ -196,13 +193,10 @@ describe('app-dir - errors', () => {
) )
) )
} else { } else {
expect(cleanCliOutput).toMatchInlineSnapshot(` expect(cleanCliOutput).toContain('⨯ Error: null')
"⨯ Error: null // No runtime sourcemapping so the stack is just a bunch of library internals
at ignore-listed frames { expect(cleanCliOutput).toContain("digest: '<digest>'")
digest: '<digest>' expect(cleanCliOutput).not.toContain('ignore-listed frames')
}
"
`)
} }
}) })
...@@ -229,13 +223,10 @@ describe('app-dir - errors', () => { ...@@ -229,13 +223,10 @@ describe('app-dir - errors', () => {
expect.stringMatching(/Error: this is a test.*digest: '<digest>'/s) expect.stringMatching(/Error: this is a test.*digest: '<digest>'/s)
) )
} else { } else {
expect(cleanCliOutput).toMatchInlineSnapshot(` expect(cleanCliOutput).toContain('⨯ Error: this is a test')
"⨯ Error: this is a test // No runtime sourcemapping so the stack is just a bunch of library internals
at ignore-listed frames { expect(cleanCliOutput).toContain("digest: '<digest>'")
digest: '<digest>' expect(cleanCliOutput).not.toContain('ignore-listed frames')
}
"
`)
} }
}) })
......
...@@ -37,7 +37,7 @@ describe('proxy-runtime', () => { ...@@ -37,7 +37,7 @@ describe('proxy-runtime', () => {
4 | 4 |
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time. The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
at ignore-listed frames" at printBuildErrors (<next-internal>)"
`) `)
} else { } else {
expect(cliOutput).toContain( expect(cliOutput).toContain(
...@@ -71,8 +71,20 @@ function getBuildError(cliOutput: string): string { ...@@ -71,8 +71,20 @@ function getBuildError(cliOutput: string): string {
} }
if (capturing) { if (capturing) {
if (line.includes('at turbopackBuild')) {
break
}
if (line) { if (line) {
lines.push(line) lines.push(
// Framework frames are intentionally printed unsourcemapped (the
// build process has no source maps); their install-specific paths
// are not stable.
line.replace(
/(at (?:async )?[\w$.]+) \([^)]*node_modules\/next\/dist[^)]*\)/,
'$1 (<next-internal>)'
)
)
} }
} else if (line.includes('Build error occurred')) { } else if (line.includes('Build error occurred')) {
capturing = true capturing = true
......
...@@ -95,7 +95,7 @@ describe('use-cache-segment-configs', () => { ...@@ -95,7 +95,7 @@ describe('use-cache-segment-configs', () => {
3 | export default function Page() { 3 | export default function Page() {
4 | return <div>This page uses \`export const runtime\`.</div> 4 | return <div>This page uses \`export const runtime\`.</div>
Ecmascript file had an error Ecmascript file had an error
at ignore-listed frames" at printBuildErrors (<next-internal>)"
`) `)
} else if (isTurbopack) { } else if (isTurbopack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
...@@ -111,8 +111,7 @@ describe('use-cache-segment-configs', () => { ...@@ -111,8 +111,7 @@ describe('use-cache-segment-configs', () => {
Ecmascript file had an error Ecmascript file had an error
at ignore-listed frames at printBuildErrors (<next-internal>)"
"
`) `)
} else if (isRspack) { } else if (isRspack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
...@@ -196,12 +195,24 @@ function getBuildOutput(cliOutput: string, isNextDeploy: boolean): string { ...@@ -196,12 +195,24 @@ function getBuildOutput(cliOutput: string, isNextDeploy: boolean): string {
break break
} }
if (!skipLines) { if (!skipLines) {
if (line.includes('at turbopackBuild')) {
break
}
if (line.includes('__next_edge_ssr_entry__')) { if (line.includes('__next_edge_ssr_entry__')) {
lines.push( lines.push(
'// TODO(veil): Fix broken import trace for Webpack loader resource.' '// TODO(veil): Fix broken import trace for Webpack loader resource.'
) )
} else { } else {
lines.push(stripAnsi(line)) lines.push(
// Framework frames are intentionally printed unsourcemapped (the
// build process has no source maps); their install-specific paths
// are not stable.
stripAnsi(line).replace(
/(at (?:async )?[\w$.]+) \([^)]*node_modules\/next\/dist[^)]*\)/,
'$1 (<next-internal>)'
)
)
} }
} else if ( } else if (
line.includes('Build error occurred') || line.includes('Build error occurred') ||
......
...@@ -41,8 +41,7 @@ describe('use-cache-unknown-cache-kind', () => { ...@@ -41,8 +41,7 @@ describe('use-cache-unknown-cache-kind', () => {
Ecmascript file had an error Ecmascript file had an error
at ignore-listed frames at printBuildErrors (<next-internal>)"
"
`) `)
} else if (isRspack) { } else if (isRspack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
...@@ -201,7 +200,15 @@ function getBuildOutput(cliOutput: string): string { ...@@ -201,7 +200,15 @@ function getBuildOutput(cliOutput: string): string {
break break
} }
lines.push(stripAnsi(line)) lines.push(
// Framework frames are intentionally printed unsourcemapped (the build
// process has no source maps); their install-specific paths are not
// stable.
stripAnsi(line).replace(
/(at (?:async )?[\w$.]+) \([^)]*node_modules\/next\/dist[^)]*\)/,
'$1 (<next-internal>)'
)
)
} else if ( } else if (
line.includes('Build error occurred') || line.includes('Build error occurred') ||
line.includes('Failed to compile') line.includes('Failed to compile')
......
...@@ -44,9 +44,9 @@ describe('use-cache-without-experimental-flag', () => { ...@@ -44,9 +44,9 @@ describe('use-cache-without-experimental-flag', () => {
expect(buildOutput).toContain('Ecmascript file had an error') expect(buildOutput).toContain('Ecmascript file had an error')
expect(buildOutput).toContain('./app/page.tsx:1:1') expect(buildOutput).toContain('./app/page.tsx:1:1')
expect(buildOutput).toContain("> 1 | 'use cache'") expect(buildOutput).toContain("> 1 | 'use cache'")
// The stack of a build error holds framework frames only, and the // The stack of a build error holds framework frames only, printed
// terminal collapses them. // unsourcemapped since the build process has no source maps.
expect(buildOutput).toContain('at ignore-listed frames') expect(buildOutput).toContain('at printBuildErrors (<next-internal>)')
} else if (isRspack) { } else if (isRspack) {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
" "
...@@ -191,7 +191,15 @@ function getBuildOutput(cliOutput: string): string { ...@@ -191,7 +191,15 @@ function getBuildOutput(cliOutput: string): string {
break break
} }
lines.push(stripAnsi(line)) lines.push(
// Framework frames are intentionally printed unsourcemapped (the build
// process has no source maps); their install-specific paths are not
// stable.
stripAnsi(line).replace(
/(at (?:async )?[\w$.]+) \([^)]*node_modules\/next\/dist[^)]*\)/,
'$1 (<next-internal>)'
)
)
} else if ( } else if (
line.includes('Build error occurred') || line.includes('Build error occurred') ||
line.includes('Failed to compile') line.includes('Failed to compile')
......
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