question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Console plugin stringify on error produces empty object

See original GitHub issue

Executing following code

try {
  throw new TypeError("my message");
} catch (error: unknown) {
  console.error(error);
}

produces following code in DevTools console (stack trace not relevant)

TypeError: my message
    at ThreadDevInfo.tsx:182:10
    at invokePassiveEffectCreate (react-dom.development.js:23487:20)
    at HTMLUnknownElement.callCallback2 (react-dom.development.js:3945:14)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:16)
    at invokeGuardedCallback (react-dom.development.js:4056:31)
    at flushPassiveEffectsImpl (react-dom.development.js:23574:9)
    at unstable_runWithPriority (scheduler.development.js:468:12)
    at runWithPriority$1 (react-dom.development.js:11276:10)
    at flushPassiveEffects (react-dom.development.js:23447:14)
    at react-dom.development.js:23324:11

but console plugin produces something like this

{
    "plugin": "rrweb/console@1",
    "payload": {
        "level": "error",
        "trace": [
            "https://jam.test:3000/src/components/Thread/ThreadDevInfo.tsx?t=1643212045995:136:15",
            "invokePassiveEffectCreate (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:16757:28)",
            "HTMLUnknownElement.callCallback2 (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:3671:22)",
            "Object.invokeGuardedCallbackDev (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:3696:24)",
            "invokeGuardedCallback (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:3730:39)",
            "flushPassiveEffectsImpl (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:16819:17)",
            "unstable_runWithPriority (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:346:20)",
            "runWithPriority$1 (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:8468:18)",
            "flushPassiveEffects (https://jam.test:3000/node_modules/.vite/chunk-BPLMWNAK.js?v=be0ca6f3:16723:22)"
        ],
        "payload": [
            "{}"
        ]
    }
}

as you see payload is equal to {} which means there were no keys found inside Error.

I found this code responsible for Event stringify: https://github.com/rrweb-io/rrweb/blob/master/packages/rrweb/src/plugins/console/record/stringify.ts#L121-L133. Doing naive SO search I found this response: https://stackoverflow.com/questions/18277890/why-cant-i-see-the-keys-of-an-error-object which should work for Error as well.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
baransucommented, Jan 26, 2022

Probably doing something like

if(value instanceof Error) {
  return value.name + ": " + value.message
}

should be simple and effective solution 🤔

0reactions
LeeRaynocommented, Feb 22, 2022

我们这个一般多久发一版了。希望能尽快发一版,感谢!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it not possible to stringify an Error using JSON.stringify?
The problem is that I end up with an empty object. What I've tried. Browsers. I first tried leaving node.js and running it...
Read more >
How to fix JSON.stringify returning an empty object
I am developing a chrome extension that makes the internet private again. No tracking, no bad actors, etc. I have written a few...
Read more >
Beware of Using JSON.stringify() for Logging - Level Up Coding
It uses the console object along with JSON.stringify() to log messages and ... The output from using JSON.stringify() with an error is an...
Read more >
request.log(err) show an empty object · Issue #2744 · hapijs/hapi
I propose that stringifying a console.error is wrong, since it can't show linebreaks, so an error.stack looks bad, it should ju...
Read more >
5.x API - Express.js
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ), or an empty...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found