Suppress known/expected warnings and errors in local DEV shell
Brian Vaughn committed
Aug 4, 2019 at 14:33 UTC
6b3ae6459819065b047244db43d432da2a7be6a1
2 files changed
+38
shells/dev/app/console.js
new
+27
@@ -0,0 +1,27 @@
1
+// @flow
2
+
3
+function ignoreStrings(
4
+ methodName: string,
5
+ stringsToIgnore: Array<string>
6
+): void {
7
+ const originalMethod = console[methodName];
8
+ console[methodName] = (...args) => {
9
+ const maybeString = args[0];
10
+ if (typeof maybeString === 'string') {
11
+ for (let i = 0; i < stringsToIgnore.length; i++) {
12
+ if (maybeString.startsWith(stringsToIgnore[i])) {
13
+ return;
14
+ }
15
+ }
16
+ }
17
+ originalMethod(...args);
18
+ };
19
+}
20
+
21
+export function ignoreErrors(errorsToIgnore: Array<string>): void {
22
+ ignoreStrings('error', errorsToIgnore);
23
+}
24
+
25
+export function ignoreWarnings(warningsToIgnore: Array<string>): void {
26
+ ignoreStrings('warn', warningsToIgnore);
27
+}
shells/dev/app/index.js
+11
@@ -19,9 +19,20 @@ import ReactNativeWeb from './ReactNativeWeb';
19
import ToDoList from './ToDoList';
20
import Toggle from './Toggle';
21
import SuspenseTree from './SuspenseTree';
22
+import { ignoreErrors, ignoreWarnings } from './console';
23
24
import './styles.css';
25
26
+// DevTools intentionally tests compatibility with certain legacy APIs.
27
+// Suppress their error messages in the local dev shell,
28
+// because they might mask other more serious error messages.
29
+ignoreErrors([
30
+ 'Warning: Legacy context API',
31
+ 'Warning: Unsafe lifecycle methods',
32
+ 'Warning: %s is deprecated in StrictMode.', // findDOMNode
33
+]);
34
+ignoreWarnings(['Warning: componentWillReceiveProps is deprecated']);
35
+
36
const roots = [];
37
38
function mountHelper(App) {