Skip to content

Commit 398bdf4

Browse files
targoscodebytere
authored andcommitted
perf_hooks: fix error message for invalid entryTypes
Will now print a more meaningful value instead of always [object Object] PR-URL: #33285 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent ba66b21 commit 398bdf4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/perf_hooks.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,20 @@ class PerformanceObserver extends AsyncResource {
341341
if (typeof options !== 'object' || options === null) {
342342
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
343343
}
344-
if (!ArrayIsArray(options.entryTypes)) {
345-
throw new ERR_INVALID_OPT_VALUE('entryTypes', options);
344+
const { entryTypes } = options;
345+
if (!ArrayIsArray(entryTypes)) {
346+
throw new ERR_INVALID_OPT_VALUE('entryTypes', entryTypes);
346347
}
347-
const entryTypes = options.entryTypes.filter(filterTypes).map(mapTypes);
348-
if (entryTypes.length === 0) {
348+
const filteredEntryTypes = entryTypes.filter(filterTypes).map(mapTypes);
349+
if (filteredEntryTypes.length === 0) {
349350
throw new ERR_VALID_PERFORMANCE_ENTRY_TYPE();
350351
}
351352
this.disconnect();
352353
const observerCountsGC = observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC];
353354
this[kBuffer][kEntries] = [];
354355
L.init(this[kBuffer][kEntries]);
355356
this[kBuffering] = Boolean(options.buffered);
356-
for (const entryType of entryTypes) {
357+
for (const entryType of filteredEntryTypes) {
357358
const list = getObserversList(entryType);
358359
if (this[kTypes][entryType]) continue;
359360
const item = { obs: this };

test/parallel/test-performanceobserver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
5858
{
5959
code: 'ERR_INVALID_OPT_VALUE',
6060
name: 'TypeError',
61-
message: 'The value "[object Object]" is invalid ' +
61+
message: `The value "${i}" is invalid ` +
6262
'for option "entryTypes"'
6363
});
6464
});

0 commit comments

Comments
 (0)