Menu

1 / 4

Your Error Lost Its Cause Somewhere Between the Catch and the Log

JavaScript in Plain English - Medium·Ferid Brković·4 days ago
#qcMAgfVr
Reading 0:00
15s threshold

Member-only story

Your Error Lost Its Cause Somewhere Between the Catch and the Log

Error cause keeps the original failure. JSON.stringify, spread and err.stack quietly drop it. Here is how to keep it.

Ferid Brković

6 min read6 hours ago

Press enter or click to view image in full size

The alert says “Could not load user 7”. The log line says the same. Somewhere below it a database connection was refused, a DNS lookup failed or a certificate expired, and none of that made it into the record you are now reading at two in the morning.

The message was improved on purpose. Somebody caught a low-level error and threw a clearer one. That is good practice, and it is also the moment the real reason usually disappears.

JavaScript has had a standard fix for this since 2021: the cause option on Error . Using it is one line.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.