Why logging errors in JavaScript can silently produce empty objects like {}
A developer discovered that an integration failure alert was logging only '{}' instead of a useful error message, prompting an investigation into why. The root cause lies in how JavaScript's JSON.stringify works: it only serializes own, enumerable properties, and Error objects have non-enumerable message and stack fields. This means that while err.message and console.error work correctly, passing an Error through JSON serialization silently strips all useful information. The behavior is by design in the language specification, not a bug in Node.js or any logger. The author warns that empty error logs should be treated as bugs themselves, since they mask real failures and can recur undetected.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in