Skip to content

Commit 1d3e595

Browse files
committed
note that Error objects are auto-serialized in JSONConsumer
1 parent c05dcfc commit 1d3e595

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

doc/api/logger.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ JSON-serializable will cause an error at log time:
560560
* Functions are silently omitted by `JSON.stringify()`.
561561
* Circular references throw a `TypeError`.
562562
563+
`Error` objects are an exception to this rule. Although `JSON.stringify()`
564+
serializes `Error` instances as `'{}'` (because their properties are
565+
non-enumerable), the logger handles them automatically using the built-in
566+
[`stdSerializers.err()`][] serializer, which extracts `type`, `message`,
567+
`stack`, and the `cause` chain.
568+
563569
To log `BigInt` values, convert them to strings or numbers first:
564570
565571
```js
@@ -898,4 +904,5 @@ consumer.attach();
898904
```
899905

900906
[RFC 5424]: https://www.rfc-editor.org/rfc/rfc5424.html
907+
[`stdSerializers.err()`]: #stdserializerserrerror
901908
[`util.inspect.custom`]: util.md#utilinspectcustom

0 commit comments

Comments
 (0)