| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b1a6ffa commit a8a0603
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,6 +88,7 @@ const { | |||
| 88 | 88 | StringPrototypePadEnd, | |
| 89 | 89 | StringPrototypePadStart, | |
| 90 | 90 | StringPrototypeRepeat, | |
| 91 | + StringPrototypeReplace, | ||
| 91 | 92 | StringPrototypeReplaceAll, | |
| 92 | 93 | StringPrototypeSlice, | |
| 93 | 94 | StringPrototypeSplit, | |
@@ -733,6 +734,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) { | |||
| 733 | 734 | } while (++depth !== 3); | |
| 734 | 735 | } | |
| 735 | 736 | ||
| 737 | + /** @type {(constructor: string, tag: string, fallback: string, size?: string) => string} */ | ||
| 736 | 738 | function getPrefix(constructor, tag, fallback, size = '') { | |
| 737 | 739 | if (constructor === null) { | |
| 738 | 740 | if (tag !== '' && fallback !== tag) { | |
@@ -1316,11 +1318,20 @@ function getStackFrames(ctx, err, stack) { | |||
| 1316 | 1318 | return frames; | |
| 1317 | 1319 | } | |
| 1318 | 1320 | ||
| 1321 | + /** @type {(stack: string, constructor: string | null, name: unknown, tag: string) => string} */ | ||
| 1319 | 1322 | function improveStack(stack, constructor, name, tag) { | |
| 1320 | 1323 | // A stack trace may contain arbitrary data. Only manipulate the output | |
| 1321 | 1324 | // for "regular errors" (errors that "look normal") for now. | |
| 1322 | 1325 | let len = name.length; | |
| 1323 | 1326 | ||
| 1327 | + if (typeof name !== 'string') { | ||
| 1328 | + stack = StringPrototypeReplace( | ||
| 1329 | + stack, | ||
| 1330 | + `${name}`, | ||
| 1331 | + `${name} [${StringPrototypeSlice(getPrefix(constructor, tag, 'Error'), 0, -1)}]`, | ||
| 1332 | + ); | ||
| 1333 | + } | ||
| 1334 | + | ||
| 1324 | 1335 | if (constructor === null || | |
| 1325 | 1336 | (StringPrototypeEndsWith(name, 'Error') && | |
| 1326 | 1337 | StringPrototypeStartsWith(stack, name) && | |
@@ -1353,8 +1364,8 @@ function removeDuplicateErrorKeys(ctx, keys, err, stack) { | |||
| 1353 | 1364 | if (!ctx.showHidden && keys.length !== 0) { | |
| 1354 | 1365 | for (const name of ['name', 'message', 'stack']) { | |
| 1355 | 1366 | const index = ArrayPrototypeIndexOf(keys, name); | |
| 1356 | - // Only hide the property in case it's part of the original stack | ||
| 1357 | - if (index !== -1 && StringPrototypeIncludes(stack, err[name])) { | ||
| 1367 | + // Only hide the property if it's a string and if it's part of the original stack | ||
| 1368 | + if (index !== -1 && (typeof err[name] !== 'string' || StringPrototypeIncludes(stack, err[name]))) { | ||
| 1358 | 1369 | ArrayPrototypeSplice(keys, index, 1); | |
| 1359 | 1370 | } | |
| 1360 | 1371 | } | |
@@ -1414,7 +1425,7 @@ function safeGetCWD() { | |||
| 1414 | 1425 | } | |
| 1415 | 1426 | ||
| 1416 | 1427 | function formatError(err, constructor, tag, ctx, keys) { | |
| 1417 | - const name = err.name != null ? String(err.name) : 'Error'; | ||
| 1428 | + const name = err.name != null ? err.name : 'Error'; | ||
| 1418 | 1429 | let stack = getStackString(err); | |
| 1419 | 1430 | ||
| 1420 | 1431 | removeDuplicateErrorKeys(ctx, keys, err, stack); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -770,14 +770,14 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324'); | |||
| 770 | 770 | // Note: Symbols are not supported by `Error#toString()` which is called by | |
| 771 | 771 | // accessing the `stack` property. | |
| 772 | 772 | [ | |
| 773 | - [404, '404: foo', '[404]'], | ||
| 774 | - [0, '0: foo', '[RangeError: foo]'], | ||
| 775 | - [0n, '0: foo', '[RangeError: foo]'], | ||
| 773 | + [404, '404 [RangeError]: foo', '[404]'], | ||
| 774 | + [0, '0 [RangeError]: foo', '[RangeError: foo]'], | ||
| 775 | + [0n, '0 [RangeError]: foo', '[RangeError: foo]'], | ||
| 776 | 776 | [null, 'null: foo', '[RangeError: foo]'], | |
| 777 | 777 | [undefined, 'RangeError: foo', '[RangeError: foo]'], | |
| 778 | - [false, 'false: foo', '[RangeError: foo]'], | ||
| 778 | + [false, 'false [RangeError]: foo', '[RangeError: foo]'], | ||
| 779 | 779 | ['', 'foo', '[RangeError: foo]'], | |
| 780 | - [[1, 2, 3], '1,2,3: foo', '[1,2,3]'], | ||
| 780 | + [[1, 2, 3], '1,2,3 [RangeError]: foo', '[1,2,3]'], | ||
| 781 | 781 | ].forEach(([value, outputStart, stack]) => { | |
| 782 | 782 | let err = new RangeError('foo'); | |
| 783 | 783 | err.name = value; | |
@@ -3404,3 +3404,15 @@ assert.strictEqual( | |||
| 3404 | 3404 | '[Function: Symbol(f)]', | |
| 3405 | 3405 | ); | |
| 3406 | 3406 | } | |
| 3407 | + | ||
| 3408 | + { | ||
| 3409 | + const error = new EvalError(); | ||
| 3410 | + const re = /a/g; | ||
| 3411 | + error.name = re; | ||
| 3412 | + assert.strictEqual(error.name, re); | ||
| 3413 | + assert.strictEqual( | ||
| 3414 | + util.inspect(error), | ||
| 3415 | + `${re} [EvalError] | ||
| 3416 | + ${error.stack.split('\n').slice(1).join('\n')}`, | ||
| 3417 | + ); | ||
| 3418 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments