Skip to content

Commit 5094965

Browse files
Add
1 parent bc73890 commit 5094965

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

example/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
import { installConsoleSymbolicator } from 'react-native-console-symbolicator';
1010
import Button from './components/Button';
1111

12-
installConsoleSymbolicator();
12+
installConsoleSymbolicator({
13+
excludeReactNativeCoreFrames: true,
14+
});
1315

1416
const message =
1517
'When reading this error in React Native Dev Tools, you should see the original source code location instead of the bundle.';

src/index.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import parseErrorStack from 'react-native/Libraries/Core/Devtools/parseErrorStac
33

44
type ConsoleLogFunction = (...args: unknown[]) => void;
55

6-
export const installConsoleSymbolicator = () => {
6+
export const installConsoleSymbolicator = ({
7+
excludeReactNativeCoreFrames = false,
8+
}: {
9+
excludeReactNativeCoreFrames?: boolean;
10+
} = {}) => {
711
if (!__DEV__) {
812
return;
913
}
@@ -18,7 +22,10 @@ export const installConsoleSymbolicator = () => {
1822
};
1923

2024
const makeSymbolicatedConsole = (fn: ConsoleLogFunction) =>
21-
symbolicatedConsole(fn, originalConsole.error);
25+
symbolicatedConsole(fn, {
26+
logError: originalConsole.error,
27+
excludeReactNativeCoreFrames,
28+
});
2229

2330
console.error = makeSymbolicatedConsole(originalConsole.error);
2431
console.warn = makeSymbolicatedConsole(originalConsole.warn);
@@ -31,7 +38,16 @@ export const installConsoleSymbolicator = () => {
3138
};
3239

3340
const symbolicatedConsole =
34-
(original: ConsoleLogFunction, logError: ConsoleLogFunction) =>
41+
(
42+
original: ConsoleLogFunction,
43+
{
44+
logError,
45+
excludeReactNativeCoreFrames,
46+
}: {
47+
logError: ConsoleLogFunction;
48+
excludeReactNativeCoreFrames: boolean;
49+
}
50+
) =>
3551
async (...args: unknown[]) => {
3652
const symbolicating: Array<Promise<unknown>> = args.map(async (arg) => {
3753
if (!(arg instanceof Error) || !arg.stack) {
@@ -66,6 +82,11 @@ const symbolicatedConsole =
6682
return ` at ${frame.methodName} (${fileInfo})`;
6783
}
6884
)
85+
.filter(
86+
(line: string) =>
87+
!excludeReactNativeCoreFrames ||
88+
!line.includes('node_modules/react-native')
89+
)
6990
.join('\n');
7091

7192
arg.stack = arg.message ? `${arg.message}\n${newStack}` : newStack;

0 commit comments

Comments
 (0)