MCPcopy Index your code
hub / github.com/react/react / formatOwnerStack

Function formatOwnerStack

packages/shared/ReactOwnerStackFrames.js:12–41  ·  view source on GitHub ↗
(error: Error)

Source from the content-addressed store, hash-verified

10import DefaultPrepareStackTrace from 'shared/DefaultPrepareStackTrace';
11
12export function formatOwnerStack(error: Error): string {
13 const prevPrepareStackTrace = Error.prepareStackTrace;
14 Error.prepareStackTrace = DefaultPrepareStackTrace;
15 let stack = error.stack;
16 Error.prepareStackTrace = prevPrepareStackTrace;
17 if (stack.startsWith('Error: react-stack-top-frame\n')) {
18 // V8's default formatting prefixes with the error message which we
19 // don't want/need.
20 stack = stack.slice(29);
21 }
22 let idx = stack.indexOf('\n');
23 if (idx !== -1) {
24 // Pop the JSX frame.
25 stack = stack.slice(idx + 1);
26 }
27 idx = stack.indexOf('react_stack_bottom_frame');
28 if (idx !== -1) {
29 idx = stack.lastIndexOf('\n', idx);
30 }
31 if (idx !== -1) {
32 // Cut off everything after the bottom frame since it'll be internals.
33 stack = stack.slice(0, idx);
34 } else {
35 // We didn't find any internal callsite out to user space.
36 // This means that this was called outside an owner or the owner is fully internal.
37 // To keep things light we exclude the entire trace in this case.
38 return '';
39 }
40 return stack;
41}

Calls

no outgoing calls

Tested by

no test coverage detected