Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bcbf176

Browse filesBrowse 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
Copy full SHA for bcbf176

File tree

Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed
Open diff view settings
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+5-3Lines 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
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 ` +
Collapse file

‎test/parallel/test-errors-systemerror.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-errors-systemerror.js
+1-1Lines changed: 1 addition & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.