Skip to content

Commit bcbf176

Browse files
aduh95codebytere
authored andcommitted
errors: refactor to use more primordials
PR-URL: #36167 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 545ac1f commit bcbf176

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎lib/internal/errors.js‎

Lines changed: 5 additions & 3 deletions
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
returnerrorString;
9899
}
99-
return`${errorString}\n at ${trace.join('\n at ')}`;
100+
return`${errorString}\n at ${ArrayPrototypeJoin(trace,'\n at ')}`;
100101
};
101102

102103
constmaybeOverridePrepareStackTrace=(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-
returnmsg.apply(self,args);
380+
returnReflectApply(msg,self,args);
380381
}
381382

382-
constexpectedLength=(msg.match(/%[dfijoOs]/g)||[]).length;
383+
constexpectedLength=
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assert.throws(
99
()=>{newSystemError();},
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)