Skip to content

Commit

Permalink
align turbopack
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 27, 2024
1 parent 42bc72a commit 54c13a9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 ?? '<unknown>',
ignored,
arguments: [],
}

return {
frame: ignorableFrame,
Expand Down Expand Up @@ -264,33 +275,17 @@ async function createOriginalStackFrame(
project: Project,
frame: TurbopackStackFrame
): Promise<OriginalStackFrameResponse | null> {
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),
}
}

Expand Down
32 changes: 16 additions & 16 deletions test/development/errors/node-internal-stack-frame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down

0 comments on commit 54c13a9

Please sign in to comment.