From 9b11bdb001ff8b45b067ee9967c154481b9ac854 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 29 Oct 2019 21:24:23 +0100 Subject: [PATCH] v8: inspect unserializable objects This would otherwise sometimes just print relatively useless information about the value in question, such as `[object Object]`. PR-URL: https://github.com/nodejs/node/pull/30167 Reviewed-By: Colin Ihrig Reviewed-By: Gus Caplan Reviewed-By: David Carlier --- lib/v8.js | 4 +++- test/parallel/test-v8-serdes.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/v8.js b/lib/v8.js index 1a8c70c6d75d3f..5be59cb935cfcf 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -24,6 +24,7 @@ const { } = internalBinding('serdes'); const assert = require('internal/assert'); const { copy } = internalBinding('buffer'); +const { inspect } = require('internal/util/inspect'); const { FastBuffer } = require('internal/buffer'); const { getValidatedPath } = require('internal/fs/utils'); const { toNamespacedPath } = require('path'); @@ -242,7 +243,8 @@ class DefaultSerializer extends Serializer { i = arrayBufferViewTypeToIndex.get(tag); if (i === undefined) { - throw new this._getDataCloneError(`Unknown host object type: ${tag}`); + throw new this._getDataCloneError( + `Unserializable host object: ${inspect(abView)}`); } } this.writeUint32(i); diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 58b919066ea990..a992ba42ce46bf 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -156,8 +156,10 @@ const deserializerTypeError = } { - assert.throws(() => v8.serialize(hostObject), - /^Error: Unknown host object type: \[object .*\]$/); + assert.throws(() => v8.serialize(hostObject), { + constructor: Error, + message: 'Unserializable host object: JSStream {}' + }); } {