MCPcopy Index your code
hub / github.com/nodejs/node / improveStack

Function improveStack

lib/internal/util/inspect.js:1811–1850  ·  view source on GitHub ↗

@type {(stack: string, constructor: string | null, name: unknown, tag: string) => string}

(stack, constructor, name, tag)

Source from the content-addressed store, hash-verified

1809
1810/** @type {(stack: string, constructor: string | null, name: unknown, tag: string) => string} */
1811function improveStack(stack, constructor, name, tag) {
1812 // A stack trace may contain arbitrary data. Only manipulate the output
1813 // for "regular errors" (errors that "look normal") for now.
1814 let len = name.length;
1815
1816 if (typeof name !== 'string') {
1817 stack = StringPrototypeReplace(
1818 stack,
1819 `${name}`,
1820 `${name} [${StringPrototypeSlice(getPrefix(constructor, tag, 'Error'), 0, -1)}]`,
1821 );
1822 }
1823
1824 if (constructor === null ||
1825 (StringPrototypeEndsWith(name, 'Error') &&
1826 StringPrototypeStartsWith(stack, name) &&
1827 (stack.length === len || stack[len] === ':' || stack[len] === '\n'))) {
1828 let fallback = 'Error';
1829 if (constructor === null) {
1830 const start = RegExpPrototypeExec(/^([A-Z][a-z_ A-Z0-9[\]()-]+)(?::|\n {4}at)/, stack) ||
1831 RegExpPrototypeExec(/^([a-z_A-Z0-9-]*Error)$/, stack);
1832 fallback = (start?.[1]) || '';
1833 len = fallback.length;
1834 fallback ||= 'Error';
1835 }
1836 const prefix = StringPrototypeSlice(getPrefix(constructor, tag, fallback), 0, -1);
1837 if (name !== prefix) {
1838 if (StringPrototypeIncludes(prefix, name)) {
1839 if (len === 0) {
1840 stack = `${prefix}: ${stack}`;
1841 } else {
1842 stack = `${prefix}${StringPrototypeSlice(stack, len)}`;
1843 }
1844 } else {
1845 stack = `${prefix} [${name}]${StringPrototypeSlice(stack, len)}`;
1846 }
1847 }
1848 }
1849 return stack;
1850}
1851
1852function markNodeModules(ctx, line) {
1853 let tempLine = '';

Callers 1

formatErrorFunction · 0.85

Calls 1

getPrefixFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…