Repository navigation
Error stacks in log includes null.thing instead of just thing #42417
Copy link
Copy link
Closed
Description
Version
v17.4.0
Platform
Darwin Mac-mini.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:29:10 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T8101 arm64
Subsystem
No response
What steps will reproduce the bug?
git clone git@github.com:virtualstate/focus.git
cd focus
git checkout 07998653ea604a44e15d31e66fa4e3e6c72c06be
yarn
yarn testYou will see the last log being:
[
{ value: [Object], status: 'fulfilled' },
{
reason: /Users/fabiancook/src/virtualstate/focus/src/tests/throw.tsx:5
throw new Error();
^
Error
at null.Throw1 (/Users/fabiancook/src/virtualstate/focus/src/tests/throw.tsx:5:11)
at Object.[Symbol.asyncIterator] (/Users/fabiancook/src/virtualstate/focus/src/component.ts:32:22)
at AsyncGenerator.next (<anonymous>)
at null.childrenSettledGeneratorInner (/Users/fabiancook/src/virtualstate/focus/src/children.ts:135:24)
at childrenSettledGeneratorInner.next (<anonymous>)
at null.childrenSettledGeneratorInner (/Users/fabiancook/src/virtualstate/focus/src/children.ts:131:14)
at childrenSettledGeneratorInner.next (<anonymous>)
at null.childrenSettledGenerator (/Users/fabiancook/src/virtualstate/focus/src/children.ts:112:22)
at childrenSettledGenerator.next (<anonymous>)
at null.<anonymous> (/Users/fabiancook/src/virtualstate/focus/src/children.ts:187:28),
status: 'rejected'
}
]
]or the smaller case:
try {
async function Throw1() {
throw new Error();
}
await Throw1();
} catch (error) {
console.error(error)
}Logs
Error
at null.Throw1 (/Users/fabiancook/src/virtualstate/fringe/src/tests/throw.tsx:5:11)
at null.<anonymous> (/Users/fabiancook/src/virtualstate/fringe/src/tests/throw.tsx:59:11)If I run this same code with deno, I do not see null
yarn test:deno [
{
value: { source: "child1", options: [Object], children: [Object] },
status: "fulfilled"
},
{
reason: Error
at Throw1 (file:///Users/fabiancook/src/virtualstate/fringe/esnext/tests/throw.js:4:11)
at Object.[Symbol.asyncIterator] (file:///Users/fabiancook/src/virtualstate/fringe/esnext/component.js:25:28)
at AsyncGenerator.next (<anonymous>)
at childrenSettledGeneratorInner (file:///Users/fabiancook/src/virtualstate/fringe/esnext/children.js:62:30)
at childrenSettledGeneratorInner.next (<anonymous>)
at childrenSettledGeneratorInner (file:///Users/fabiancook/src/virtualstate/fringe/esnext/children.js:56:20)
at childrenSettledGeneratorInner.next (<anonymous>)
at childrenSettledGenerator (file:///Users/fabiancook/src/virtualstate/fringe/esnext/children.js:43:26)
at childrenSettledGenerator.next (<anonymous>)
at file:///Users/fabiancook/src/virtualstate/fringe/esnext/children.js:94:34,
status: "rejected"
}
]
]Error
at Throw1 (file:///Users/fabiancook/src/virtualstate/fringe/esnext/tests/throw.js:53:15)
at file:///Users/fabiancook/src/virtualstate/fringe/esnext/tests/throw.js:55:11How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
null does not show
What do you see instead?
null shows
Additional information
I'm reporting this because I expect showing null is not intentional.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
fabiancook commentedon Mar 21, 2022
🤦🏻
I believe this is just something to do with the source map. Disabling shows the correct error stack.
Will leave open and let someone else decide if it is still relevant to investigate for source maps, or to leave as is.
benjamingr commentedon Mar 21, 2022
@fabiancook are you using native Node sourcemaps? How is that code built? Can you reproduce this with "regular" native node source maps?
fabiancook commentedon Mar 22, 2022
These sourcemaps were generated through typescript/
tscthrow1.ts:throw1.js:throw1.js.map:node --enable-source-maps esnext/tests/throw1.js:node esnext/tests/throw1.js:What is a native node source map vs what I have here? I see in the documentation
The above has
{"version":3...}so I am hoping this is what you're looking for.benjamingr commentedon Mar 22, 2022
@bcoe hmm, the
nullshould probably be filtered here?cspotcode commentedon Mar 25, 2022
It also omits
async, so it doesn't seem to handle async stack traces correctly.$ node --version v17.4.0 $ tsc --module esnext --target esnext --sourcemap ./repro.ts $ node ./repro.js Error at loop (/app/repro.js:8:17) at async main (/app/repro.js:3:5) $ node --enable-source-maps ./repro.js Error at null.loop (/app/repro.ts:10:17) at null.main (/app/repro.ts:3:5) $ node -r @cspotcode/source-map-support/register ./repro.js Error at loop (/app/repro.ts:10:17) at async main (/app/repro.ts:3:5)cspotcode commentedon Mar 25, 2022
We have a test and bench that checks the performance and correctness of various source-map options:
https://github.com/cspotcode/source-map-performance-demo#example-output
fabiancook commentedon Mar 30, 2022
If I use
source-map-support:node -r source-map-support/register esnext/tests/index.js Error: at Throw1 (file:///Users/fabiancook/src/virtualstate/fringe/src/tests/throw.tsx:5:11) at Object.[Symbol.asyncIterator] (file:///Users/fabiancook/src/virtualstate/fringe/src/component.ts:32:22) at AsyncGenerator.next (<anonymous>) at childrenSettledGeneratorInner (file:///Users/fabiancook/src/virtualstate/fringe/src/children.ts:135:24) at childrenSettledGeneratorInner.next (<anonymous>) at childrenSettledGeneratorInner (file:///Users/fabiancook/src/virtualstate/fringe/src/children.ts:131:14) at childrenSettledGeneratorInner.next (<anonymous>) at childrenSettledGenerator (file:///Users/fabiancook/src/virtualstate/fringe/src/children.ts:112:22) at childrenSettledGenerator.next (<anonymous>) at file:///Users/fabiancook/src/virtualstate/fringe/src/children.ts:187:28benjamingr commentedon Mar 30, 2022
It looks like a simple fix in lib/internal/source_map/prepare_stack_trace.js - if t.getTypeName() returns null we should omit
null.Anyone wants to open a PR?
benjamingr commentedon Mar 30, 2022
A fix would probably but not nessarily look like this, this also needs a test:
fabiancook commentedon Mar 30, 2022
I have cloned a fresh copy of the repo, am currently building and testing
Is it possible for typeName to be an empty string? Or undefined vs null? This here would cover all I would expect.
benjamingr commentedon Mar 30, 2022
I tested locally before making that suggestion - I got either a name or
null- let me read the codebenjamingr commentedon Mar 30, 2022
It seems according to the v8 docs it's either the name or
null: .fabiancook commentedon Mar 30, 2022
using
typeName && ...is following the same asfnName || ...fabiancook commentedon Mar 30, 2022
Hmm if its always null or a truthy string then thats cool to actually reference null there instead
fabiancook commentedon Mar 30, 2022
vs
vs
What can
fnNamebe?8 remaining items
lib: source maps filter null prefix
fabiancook commentedon Apr 4, 2022
Off the back of this, I hadn't fixed while I was in there, but should
Thrownot also showasync? Is there relevant documentation on what I should be using from v8 to be able to add that to thenamePrefixas well?I had tried
t.isAsync()as per the documentation here: https://v8.dev/docs/stack-trace-api#customizing-stack-tracesBut it does not show as
asyncstill (seesyncshowing instead ofasync)I would have expected
isAsyncto returntrue, since it both usesasync, and wasawait'd (explicitly mentioned in the v8 docs)When would we ever see
isAsyncastruefrom user land, if this is not its usage?benjamingr commentedon Apr 4, 2022
Is there any chance you compiled that to a low target without async/await and the async bit only exists in the source map? If so it should probably be extracted from there? The CallSite probably has no knowledge of that at this point.
fabiancook commentedon Apr 4, 2022
Yeah there is a good chance I am targeting something without async support, its the default tsc options I used outside of defining module + esnext
@cspotcode you mentioned you had some independent tests, do any cover async as well?
benjamingr commentedon Apr 4, 2022
It's probably worth it to open a new issue with this other issue/feature-request/bug for
asyncin the ttracelib: source maps filter null prefix
lib: source maps filter null prefix
cspotcode commentedon Apr 20, 2022
The benchmark I linked does a really simple check for async stack trace handling, but it's not a rigorous test. That's all I have.
lib: source maps filter null prefix
lib: source maps filter null prefix
lib: source maps filter null prefix
lib: source maps filter null prefix
lib: source maps filter null prefix
lib: source maps filter null prefix
cspotcode commentedon Oct 11, 2022