TypeScript · correctness
no-json-stringify-error
eslint:no-json-stringify-error Disallow `JSON.stringify` on an Error value; it yields `{}` because `message`/`stack` are non-enumerable.
- Default
- error
- Fix
- none
- Languages
- typescript
Why
Native Error details are non-enumerable, so generic JSON serialization discards diagnostic information.
Fix
Serialize explicit error fields or use an error-aware serializer.
Before / after
Executed by this rule’s unit tests.
Before
Do not stringify an Error object
try { f(); } catch (err) { JSON.stringify({ error: err }); } After
Serialize an enumerable error field
try { f(); } catch (err) { JSON.stringify({ error: err.message }); } Limits
- The rule uses local syntax and naming evidence rather than type information.
Message IDs
noJsonStringifyError