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

Function getStackFrames

lib/internal/util/inspect.js:1764–1808  ·  view source on GitHub ↗
(ctx, err, stack)

Source from the content-addressed store, hash-verified

1762}
1763
1764function getStackFrames(ctx, err, stack) {
1765 const frames = StringPrototypeSplit(stack, '\n');
1766
1767 let cause;
1768 try {
1769 ({ cause } = err);
1770 } catch {
1771 // If 'cause' is a getter that throws, ignore it.
1772 }
1773
1774 // Remove stack frames identical to frames in cause.
1775 if (cause != null && isError(cause)) {
1776 const causeStack = getStackString(ctx, cause);
1777 const causeStackStart = StringPrototypeIndexOf(causeStack, '\n at');
1778 if (causeStackStart !== -1) {
1779 const causeFrames = StringPrototypeSplit(StringPrototypeSlice(causeStack, causeStackStart + 1), '\n');
1780 const { 0: len, 1: offset } = identicalSequenceRange(frames, causeFrames);
1781 if (len > 0) {
1782 const skipped = len - 2;
1783 const msg = ` ... ${skipped} lines matching cause stack trace ...`;
1784 frames.splice(offset + 1, skipped, ctx.stylize(msg, 'undefined'));
1785 }
1786 }
1787 }
1788
1789 // Remove recursive repetitive stack frames in long stacks
1790 if (frames.length > 10) {
1791 const ranges = getDuplicateErrorFrameRanges(frames);
1792
1793 for (let i = ranges.length - 3; i >= 0; i -= 3) {
1794 const offset = ranges[i];
1795 const length = ranges[i + 1];
1796 const duplicateRanges = ranges[i + 2];
1797
1798 const msg = ` ... collapsed ${length * duplicateRanges} duplicate lines ` +
1799 'matching above ' +
1800 (duplicateRanges > 1 ?
1801 `${length} lines ${duplicateRanges} times...` :
1802 'lines ...');
1803 frames.splice(offset, length * duplicateRanges, ctx.stylize(msg, 'undefined'));
1804 }
1805 }
1806
1807 return frames;
1808}
1809
1810/** @type {(stack: string, constructor: string | null, name: unknown, tag: string) => string} */
1811function improveStack(stack, constructor, name, tag) {

Callers 1

formatErrorFunction · 0.85

Calls 4

getStackStringFunction · 0.85
identicalSequenceRangeFunction · 0.85
isErrorFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…