Don't let a DevTools or React internal error interfere with logging.
Brian Vaughn committed
Aug 2, 2019 at 09:39 UTC
9727f4e88f7a9af233de07112794988ef9c1d61c
1 file changed
+36
-32
src/backend/console.js
+36
-32
@@ -83,40 +83,44 @@ export function patch(): void {
83
targetConsole[method]);
84
85
const overrideMethod = (...args) => {
86
- // If we are ever called with a string that already has a component stack, e.g. a React error/warning,
87
- // don't append a second stack.
88
- const alreadyHasComponentStack =
89
- args.length > 0 && FRAME_REGEX.exec(args[args.length - 1]);
90
-
91
- if (!alreadyHasComponentStack) {
92
- // If there's a component stack for at least one of the injected renderers, append it.
93
- // We don't handle the edge case of stacks for more than one (e.g. interleaved renderers?)
94
- for (let {
95
- getCurrentFiber,
96
- getDisplayNameForFiber,
97
- } of injectedRenderers.values()) {
98
- let current: ?Fiber = getCurrentFiber();
99
- let ownerStack: string = '';
100
- while (current != null) {
101
- const name = getDisplayNameForFiber(current);
102
- const owner = current._debugOwner;
103
- const ownerName =
104
- owner != null ? getDisplayNameForFiber(owner) : null;
105
-
106
- ownerStack += describeComponentFrame(
107
- name,
108
- current._debugSource,
109
- ownerName
110
- );
111
-
112
- current = owner;
113
- }
114
-
115
- if (ownerStack !== '') {
116
- args.push(ownerStack);
117
- break;
86
+ try {
87
+ // If we are ever called with a string that already has a component stack, e.g. a React error/warning,
88
+ // don't append a second stack.
89
+ const alreadyHasComponentStack =
90
+ args.length > 0 && FRAME_REGEX.exec(args[args.length - 1]);
91
+
92
+ if (!alreadyHasComponentStack) {
93
+ // If there's a component stack for at least one of the injected renderers, append it.
94
+ // We don't handle the edge case of stacks for more than one (e.g. interleaved renderers?)
95
+ for (let {
96
+ getCurrentFiber,
97
+ getDisplayNameForFiber,
98
+ } of injectedRenderers.values()) {
99
+ let current: ?Fiber = getCurrentFiber();
100
+ let ownerStack: string = '';
101
+ while (current != null) {
102
+ const name = getDisplayNameForFiber(current);
103
+ const owner = current._debugOwner;
104
+ const ownerName =
105
+ owner != null ? getDisplayNameForFiber(owner) : null;
106
+
107
+ ownerStack += describeComponentFrame(
108
+ name,
109
+ current._debugSource,
110
+ ownerName
111
+ );
112
+
113
+ current = owner;
114
+ }
115
+
116
+ if (ownerStack !== '') {
117
+ args.push(ownerStack);
118
+ break;
119
+ }
120
}
121
}
122
+ } catch (error) {
123
+ // Don't let a DevTools or React internal error interfere with logging.
124
}
125
126
originalMethod(...args);