-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save native stack as a separate Error
This represents the stack in the current execution environment. As opposed to the .stack property which represents the stack in the transport protocol.
- Loading branch information
1 parent
52ca0a5
commit 1794201
Showing
10 changed files
with
133 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
// TODO: Make this configurable on the Request. | ||
const externalRegExp = /\/node\_modules\/| \(node\:| node\:|\(\<anonymous\>\)/; | ||
|
||
function isNotExternal(stackFrame: string): boolean { | ||
return !externalRegExp.test(stackFrame); | ||
} | ||
|
||
function filterDebugStack(error: Error): string { | ||
// Since stacks can be quite large and we pass a lot of them, we filter them out eagerly | ||
// to save bandwidth even in DEV. We'll also replay these stacks on the client so by | ||
// stripping them early we avoid that overhead. Otherwise we'd normally just rely on | ||
// the DevTools or framework's ignore lists to filter them out. | ||
let stack = error.stack; | ||
if (stack.startsWith('Error: react-stack-top-frame\n')) { | ||
// V8's default formatting prefixes with the error message which we | ||
// don't want/need. | ||
stack = stack.slice(29); | ||
} | ||
let idx = stack.indexOf('react-stack-bottom-frame'); | ||
if (idx !== -1) { | ||
idx = stack.lastIndexOf('\n', idx); | ||
} | ||
if (idx !== -1) { | ||
// Cut off everything after the bottom frame since it'll be internals. | ||
stack = stack.slice(0, idx); | ||
} | ||
const frames = stack.split('\n').slice(1); // Pop the JSX frame. | ||
return frames.filter(isNotExternal).join('\n'); | ||
} | ||
|
||
export function formatOwnerStack(ownerStackTrace: Error): string { | ||
return filterDebugStack(ownerStackTrace); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters