Skip to content

Commit bcbf176

Browse files
aduh95codebytere
authored andcommitted
errors: refactor to use more primordials
PR-URL: #36167 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 545ac1f commit bcbf176

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/internal/errors.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const {
4040
String,
4141
StringPrototypeEndsWith,
4242
StringPrototypeIncludes,
43+
StringPrototypeMatch,
4344
StringPrototypeSlice,
4445
StringPrototypeSplit,
4546
StringPrototypeStartsWith,
@@ -96,7 +97,7 @@ const prepareStackTrace = (globalThis, error, trace) => {
9697
if (trace.length === 0) {
9798
return errorString;
9899
}
99-
return `${errorString}\n at ${trace.join('\n at ')}`;
100+
return `${errorString}\n at ${ArrayPrototypeJoin(trace, '\n at ')}`;
100101
};
101102

102103
const maybeOverridePrepareStackTrace = (globalThis, error, trace) => {
@@ -376,10 +377,11 @@ function getMessage(key, args, self) {
376377
`Code: ${key}; The provided arguments length (${args.length}) does not ` +
377378
`match the required ones (${msg.length}).`
378379
);
379-
return msg.apply(self, args);
380+
return ReflectApply(msg, self, args);
380381
}
381382

382-
const expectedLength = (msg.match(/%[dfijoOs]/g) || []).length;
383+
const expectedLength =
384+
(StringPrototypeMatch(msg, /%[dfijoOs]/g) || []).length;
383385
assert(
384386
expectedLength === args.length,
385387
`Code: ${key}; The provided arguments length (${args.length}) does not ` +

test/parallel/test-errors-systemerror.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assert.throws(
99
() => { new SystemError(); },
1010
{
1111
name: 'TypeError',
12-
message: 'Cannot read property \'match\' of undefined'
12+
message: 'String.prototype.match called on null or undefined'
1313
}
1414
);
1515

0 commit comments

Comments
 (0)