Skip to content

Commit 2b162a8

Browse files
addaleaxtargos
authored andcommitted
v8: inspect unserializable objects
This would otherwise sometimes just print relatively useless information about the value in question, such as `[object Object]`. PR-URL: #30167 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent b1f4507 commit 2b162a8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/v8.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
} = internalBinding('serdes');
2525
const assert = require('internal/assert');
2626
const { copy } = internalBinding('buffer');
27+
const { inspect } = require('internal/util/inspect');
2728
const { FastBuffer } = require('internal/buffer');
2829
const { getValidatedPath } = require('internal/fs/utils');
2930
const { toNamespacedPath } = require('path');
@@ -242,7 +243,8 @@ class DefaultSerializer extends Serializer {
242243
i = arrayBufferViewTypeToIndex.get(tag);
243244

244245
if (i === undefined) {
245-
throw new this._getDataCloneError(`Unknown host object type: ${tag}`);
246+
throw new this._getDataCloneError(
247+
`Unserializable host object: ${inspect(abView)}`);
246248
}
247249
}
248250
this.writeUint32(i);

test/parallel/test-v8-serdes.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ const deserializerTypeError =
156156
}
157157

158158
{
159-
assert.throws(() => v8.serialize(hostObject),
160-
/^Error: Unknown host object type: \[object .*\]$/);
159+
assert.throws(() => v8.serialize(hostObject), {
160+
constructor: Error,
161+
message: 'Unserializable host object: JSStream {}'
162+
});
161163
}
162164

163165
{

0 commit comments

Comments
 (0)