Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 27, 2024
1 parent 54c13a9 commit bb03e20
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ function getOriginalStackFrame(
}

// TODO: merge this section into ignoredList handling
if (
source.file === 'file://' ||
source.file?.match(/https?:\/\//)
) {
if (source.file === 'file://' || source.file?.match(/https?:\/\//)) {
return Promise.resolve({
error: false,
reason: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ function shouldIgnorePath(modulePath: string): boolean {
)
}

function createIgnoredStackFrame(
frame: TurbopackStackFrame
): IgnorableStackFrame {
return {
file: frame.file,
lineNumber: frame.line ?? 0,
column: frame.column ?? 0,
methodName: frame.methodName ?? '<unknown>',
ignored: shouldIgnorePath(frame.file),
arguments: [],
}
}

type IgnorableStackFrame = StackFrame & { ignored: boolean }

const currentSourcesByFile: Map<string, Promise<string | null>> = new Map()
Expand All @@ -60,7 +47,14 @@ export async function batchedTraceSource(
const sourceFrame = await project.traceSource(frame, currentDirectoryFileUrl)
if (!sourceFrame) {
return {
frame: createIgnoredStackFrame(frame),
frame: {
file,
lineNumber: frame.line ?? 0,
column: frame.column ?? 0,
methodName: frame.methodName ?? '<unknown>',
ignored: shouldIgnorePath(frame.file),
arguments: [],
},
source: null,
}
}
Expand Down Expand Up @@ -283,6 +277,7 @@ async function createOriginalStackFrame(
if (!traced) {
return null
}

return {
originalStackFrame: traced.frame,
originalCodeFrame: getOriginalCodeFrame(traced.frame, traced.source),
Expand Down
21 changes: 0 additions & 21 deletions test/development/acceptance/ReactRefreshLogBox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,25 +769,4 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {

expect(callStackFrames.length).toBeGreaterThan(9)
})

test('should show anonymous frames in stack trace', async () => {
await using sandbox = await createSandbox(
next,
new Map([
[
'pages/index.js',
outdent`
export default function Page() {
[1, 2, 3].map(() => {
throw new Error("anonymous error!");
})
}`,
],
])
)
const { session, browser } = sandbox
await session.assertHasRedbox()
const texts = await getRedboxCallStack(browser)
expect(texts).toMatchSnapshot()
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions test/development/errors/anonymous-stack-frame.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { nextTestSetup } from 'e2e-utils'
import { assertHasRedbox, getStackFramesContent } from 'next-test-utils'
import { outdent } from 'outdent'

describe('errors - anonymous-stack-frame', () => {
const { next } = nextTestSetup({
files: {
'pages/index.js': outdent`
export default function Page() {
[1, 2, 3].map(() => {
throw new Error("anonymous error!");
})
}`,
},
})

// TODO: hide the anonymous frames between 2 ignored frames
test('should show anonymous frames from stack trace', async () => {
const browser = await next.browser('/')

await assertHasRedbox(browser)

const stack = await getStackFramesContent(browser)
expect(stack).toMatchInlineSnapshot(`
"at Array.map ()
at Page (pages/index.js (2:13))"
`)
})
})
34 changes: 20 additions & 14 deletions test/development/errors/node-internal-stack-frame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ import {
import { outdent } from 'outdent'

describe('errors - node-internal-stack-frame', () => {
const { next } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: {
'pages/index.js': outdent`
export default function Page() {}
function createURL() {
new URL("/", "invalid")
}
export function getServerSideProps() {
new URL("/", "invalid");
return { props: {} };
createURL()
return { props: {} }
}`,
},
})

test('should hide unrelated frames in stack trace with node:internal calls', async () => {
test('should hide nodejs internal stack frames from stack trace', async () => {
const browser = await next.browser('/')

await assertHasRedbox(browser)

const stack = await getStackFramesContent(browser)
if (process.env.TURBOPACK) {
if (isTurbopack) {
// FIXME: ignore the next internal frames from node_modules
expect(stack).toMatchInlineSnapshot(`
"at new URL ()
at getServerSideProps (pages/index.js (8:3))
at <unknown> ()
at <unknown> ()
at NextTracerImpl.trace ()
at async doRender ()
at async responseGenerator ()
Expand All @@ -38,6 +45,7 @@ describe('errors - node-internal-stack-frame', () => {
at async DevServer.pipeImpl ()
at async NextNodeServer.handleCatchallRenderRequest ()
at async DevServer.handleRequestImpl ()
at async ()
at async Span.traceAsyncFn ()
at async DevServer.handleRequest ()
at async invokeRender ()
Expand All @@ -46,15 +54,13 @@ describe('errors - node-internal-stack-frame', () => {
at async Server.requestListener ()"
`)
} else {
expect(stack).toMatchInlineSnapshot(`
"at eval ()
at renderToHTMLImpl ()"
`)
}
await toggleCollapseCallStackFrames(browser)
expect(stack).toMatchInlineSnapshot(
`"at getServerSideProps (pages/index.js (8:3))"`
)

// TODO: Since there're still the locations
const expandedStack = await getStackFramesContent(browser)
expect(expandedStack).toContain(`at new URL ()`)
await toggleCollapseCallStackFrames(browser)
const stackCollapsed = await getStackFramesContent(browser)
expect(stackCollapsed).toContain('at new URL ()')
}
})
})

0 comments on commit bb03e20

Please sign in to comment.