From aae3d19338851f39e16c36245c9e85db9bdb2bd9 Mon Sep 17 00:00:00 2001 From: Michael Schramm Date: Sun, 30 Jan 2022 14:57:15 +0100 Subject: [PATCH 1/3] show [object Readable] if there is a readable object fixes https://github.com/sindresorhus/serialize-error/issues/56 --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index d794d7d..c3b04d7 100644 --- a/index.js +++ b/index.js @@ -77,6 +77,11 @@ const destroyCircular = ({ continue; } + if (typeof value === 'object' && typeof value._read === 'function' && typeof value._readableState === 'object') { + to[key] = '[object Readable]'; + continue; + } + if (typeof value === 'function') { continue; } From ed77fe0e137c78622827e013b30baa04ef120bd7 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 6 Feb 2022 11:44:38 +0700 Subject: [PATCH 2/3] Update index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index c3b04d7..f722c59 100644 --- a/index.js +++ b/index.js @@ -77,6 +77,7 @@ const destroyCircular = ({ continue; } + // TODO: Use `stream.isReadable()` when targeting Node.js 18. if (typeof value === 'object' && typeof value._read === 'function' && typeof value._readableState === 'object') { to[key] = '[object Readable]'; continue; From d1b43cb2ac1c8f8a24b2d5547ea04d7b9664b37c Mon Sep 17 00:00:00 2001 From: Michael Schramm Date: Sun, 13 Feb 2022 14:20:52 +0100 Subject: [PATCH 3/3] add test case and check for stream in general --- index.js | 4 ++-- test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f722c59..4b27091 100644 --- a/index.js +++ b/index.js @@ -78,8 +78,8 @@ const destroyCircular = ({ } // TODO: Use `stream.isReadable()` when targeting Node.js 18. - if (typeof value === 'object' && typeof value._read === 'function' && typeof value._readableState === 'object') { - to[key] = '[object Readable]'; + if (typeof value === 'object' && typeof value.pipe === 'function') { + to[key] = '[object Stream]'; continue; } diff --git a/test.js b/test.js index 0e45c35..d53d574 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,5 @@ import {Buffer} from 'node:buffer'; +import Stream from 'node:stream'; import test from 'ava'; import {serializeError, deserializeError} from './index.js'; @@ -82,6 +83,15 @@ test('should discard buffers', t => { t.deepEqual(serialized, {a: '[object Buffer]'}); }); +test('should discard streams', t => { + t.deepEqual(serializeError({s: new Stream.Stream()}), {s: '[object Stream]'}, 'Stream.Stream'); + t.deepEqual(serializeError({s: new Stream.Readable()}), {s: '[object Stream]'}, 'Stream.Readable'); + t.deepEqual(serializeError({s: new Stream.Writable()}), {s: '[object Stream]'}, 'Stream.Writable'); + t.deepEqual(serializeError({s: new Stream.Duplex()}), {s: '[object Stream]'}, 'Stream.Duplex'); + t.deepEqual(serializeError({s: new Stream.Transform()}), {s: '[object Stream]'}, 'Stream.Transform'); + t.deepEqual(serializeError({s: new Stream.PassThrough()}), {s: '[object Stream]'}, 'Stream.PassThrough'); +}); + test('should replace top-level functions with a helpful string', t => { function a() {} function b() {}