diff --git a/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts b/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts index a7262ac1a6161..1a12a294bdd0c 100644 --- a/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts +++ b/packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts @@ -19,7 +19,6 @@ import type { Project, TurbopackStackFrame } from '../../../../build/swc/types' import { getSourceMapFromFile } from '../internal/helpers/get-source-map-from-file' import { findSourceMap, type SourceMapPayload } from 'node:module' import { pathToFileURL } from 'node:url' -import isError from '../../../../lib/is-error' function shouldIgnorePath(modulePath: string): boolean { return ( @@ -88,7 +87,19 @@ export async function batchedTraceSource( } // TODO: get ignoredList from turbopack source map - const ignorableFrame = createIgnoredStackFrame(frame) + const ignorableFrame = { + file: sourceFrame.file, + lineNumber: sourceFrame.line ?? 0, + column: sourceFrame.column ?? 0, + methodName: + // We ignore the sourcemapped name since it won't be the correct name. + // The callsite will point to the column of the variable name instead of the + // name of the enclosing function. + // TODO(NDX-531): Spy on prepareStackTrace to get the enclosing line number for method name mapping. + frame.methodName ?? '', + ignored, + arguments: [], + } return { frame: ignorableFrame, @@ -264,33 +275,17 @@ async function createOriginalStackFrame( project: Project, frame: TurbopackStackFrame ): Promise { - try { - const traced = - (await nativeTraceSource(frame)) ?? - // TODO(veil): When would the bundler know more than native? - // If it's faster, try the bundler first and fall back to native later. - (await batchedTraceSource(project, frame)) - if (!traced) { - return null - } - - return { - originalStackFrame: traced.frame, - originalCodeFrame: getOriginalCodeFrame(traced.frame, traced.source), - } - } catch (e) { - // FIXME: avoid the error [Error: Unknown url scheme] { code: 'GenericFailure' } - if ( - isError(e) && - e.message === 'Unknown url scheme' && - (e as any).code === 'GenericFailure' - ) { - return { - originalStackFrame: createIgnoredStackFrame(frame), - originalCodeFrame: null, - } - } - throw e + const traced = + (await nativeTraceSource(frame)) ?? + // TODO(veil): When would the bundler know more than native? + // If it's faster, try the bundler first and fall back to native later. + (await batchedTraceSource(project, frame)) + if (!traced) { + return null + } + return { + originalStackFrame: traced.frame, + originalCodeFrame: getOriginalCodeFrame(traced.frame, traced.source), } } diff --git a/test/development/errors/node-internal-stack-frame.test.ts b/test/development/errors/node-internal-stack-frame.test.ts index 6c1a021dcd248..81b596f962740 100644 --- a/test/development/errors/node-internal-stack-frame.test.ts +++ b/test/development/errors/node-internal-stack-frame.test.ts @@ -28,22 +28,22 @@ describe('errors - node-internal-stack-frame', () => { if (process.env.TURBOPACK) { // FIXME: ignore the next internal frames from node_modules expect(stack).toMatchInlineSnapshot(` - "at getServerSideProps () - at spanContext () - at async doRender () - at async responseGenerator () - at async DevServer.renderToResponseWithComponentsImpl () - at async DevServer.renderPageComponent () - at async DevServer.renderToResponseImpl () - at async DevServer.pipeImpl () - at async NextNodeServer.handleCatchallRenderRequest () - at async DevServer.handleRequestImpl () - at async Span.traceAsyncFn () - at async DevServer.handleRequest () - at async invokeRender () - at async handleRequest () - at async requestHandlerImpl () - at async Server.requestListener ()" + "at new URL () + at NextTracerImpl.trace () + at async doRender () + at async responseGenerator () + at async DevServer.renderToResponseWithComponentsImpl () + at async DevServer.renderPageComponent () + at async DevServer.renderToResponseImpl () + at async DevServer.pipeImpl () + at async NextNodeServer.handleCatchallRenderRequest () + at async DevServer.handleRequestImpl () + at async Span.traceAsyncFn () + at async DevServer.handleRequest () + at async invokeRender () + at async handleRequest () + at async requestHandlerImpl () + at async Server.requestListener ()" `) } else { expect(stack).toMatchInlineSnapshot(`