Skip to content

Commit

Permalink
quick fix while im here
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Sep 26, 2024
1 parent 054fd12 commit 88c8fee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
18 changes: 5 additions & 13 deletions src/js/node/diagnostics_channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Reference: https://github.com/nodejs/node/blob/fb47afc335ef78a8cef7eac52b8ee7f045300696/lib/diagnostics_channel.js

const { validateFunction } = require("internal/validators");
const { ERR_INVALID_ARG_TYPE } = require("internal/errors");

const SafeMap = Map;
const SafeFinalizationRegistry = FinalizationRegistry;
Expand Down Expand Up @@ -211,7 +212,7 @@ function channel(name) {
if (channel) return channel;

if (typeof name !== "string" && typeof name !== "symbol") {
throw new ERR_INVALID_ARG_TYPE("channel", ["string", "symbol"], name);
throw ERR_INVALID_ARG_TYPE("channel", "string or symbol", name);
}

return new Channel(name);
Expand All @@ -236,7 +237,7 @@ const traceEvents = ["start", "end", "asyncStart", "asyncEnd", "error"];

function assertChannel(value, name) {
if (!(value instanceof Channel)) {
throw new ERR_INVALID_ARG_TYPE(name, ["Channel"], value);
throw ERR_INVALID_ARG_TYPE(name, ["Channel"], value);
}
}

Expand All @@ -263,7 +264,7 @@ class TracingChannel {
this.asyncEnd = asyncEnd;
this.error = error;
} else {
throw new ERR_INVALID_ARG_TYPE("nameOrChannels", ["string", "object", "Channel"], nameOrChannels);
throw ERR_INVALID_ARG_TYPE("nameOrChannels", ["string, object, or Channel"], nameOrChannels);
}
}

Expand Down Expand Up @@ -369,9 +370,7 @@ class TracingChannel {
}

const callback = ArrayPrototypeAt.$call(args, position);
if (typeof callback !== "function") {
throw new ERR_INVALID_ARG_TYPE("callback", ["function"], callback);
}
validateFunction(callback, "callback");
ArrayPrototypeSplice.$call(args, position, 1, wrappedCallback);

return start.runStores(context, () => {
Expand All @@ -392,13 +391,6 @@ function tracingChannel(nameOrChannels) {
return new TracingChannel(nameOrChannels);
}

class ERR_INVALID_ARG_TYPE extends TypeError {
constructor(name, expected, actual) {
super(`The ${name} argument must be of type ${expected}. Received type ${typeof actual}`);
this.code = "ERR_INVALID_ARG_TYPE";
}
}

export default {
channel,
hasSubscribers,
Expand Down
6 changes: 3 additions & 3 deletions test/js/node/diagnostics_channel/diagnostics_channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("Channel", () => {
expect(() => {
// @ts-expect-error
channel(null);
}).toThrow(/channel argument must be of type/);
}).toThrow(/"channel" argument must be of type string or symbol/);

checkCalls();
});
Expand Down Expand Up @@ -99,7 +99,7 @@ describe("Channel", () => {
expect(() => {
// @ts-expect-error
subscribe(name, null);
}).toThrow(/subscription argument must be of type/);
}).toThrow(/"subscription" argument must be of type/);

// Reaching zero subscribers should not delete from the channels map as there
// will be no more weakref to incRef if another subscribe happens while the
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("Channel", () => {
expect(() => {
// @ts-expect-error
subscribe(null);
}).toThrow(/channel argument must be of type/);
}).toThrow(/"channel" argument must be of type/);

checkCalls();
});
Expand Down

0 comments on commit 88c8fee

Please sign in to comment.