Skip to content

Commit 83d2837

Browse files
aduh95targos
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 0fbe945 commit 83d2837

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)=>{
@@ -372,10 +373,11 @@ function getMessage(key, args, self) {
372373
`Code: ${key}; The provided arguments length (${args.length}) does not `+
373374
`match the required ones (${msg.length}).`
374375
);
375-
returnmsg.apply(self,args);
376+
returnReflectApply(msg,self,args);
376377
}
377378

378-
constexpectedLength=(msg.match(/%[dfijoOs]/g)||[]).length;
379+
constexpectedLength=
380+
(StringPrototypeMatch(msg,/%[dfijoOs]/g)||[]).length;
379381
assert(
380382
expectedLength===args.length,
381383
`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)