Skip to content

Commit

Permalink
Suppress known/expected warnings and errors in local DEV shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Aug 4, 2019
1 parent db8542a commit 6b3ae64
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
27 changes: 27 additions & 0 deletions shells/dev/app/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow

function ignoreStrings(
methodName: string,
stringsToIgnore: Array<string>
): void {
const originalMethod = console[methodName];
console[methodName] = (...args) => {
const maybeString = args[0];
if (typeof maybeString === 'string') {
for (let i = 0; i < stringsToIgnore.length; i++) {
if (maybeString.startsWith(stringsToIgnore[i])) {
return;
}
}
}
originalMethod(...args);
};
}

export function ignoreErrors(errorsToIgnore: Array<string>): void {
ignoreStrings('error', errorsToIgnore);
}

export function ignoreWarnings(warningsToIgnore: Array<string>): void {
ignoreStrings('warn', warningsToIgnore);
}
11 changes: 11 additions & 0 deletions shells/dev/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ import ReactNativeWeb from './ReactNativeWeb';
import ToDoList from './ToDoList';
import Toggle from './Toggle';
import SuspenseTree from './SuspenseTree';
import { ignoreErrors, ignoreWarnings } from './console';

import './styles.css';

// DevTools intentionally tests compatibility with certain legacy APIs.
// Suppress their error messages in the local dev shell,
// because they might mask other more serious error messages.
ignoreErrors([
'Warning: Legacy context API',
'Warning: Unsafe lifecycle methods',
'Warning: %s is deprecated in StrictMode.', // findDOMNode
]);
ignoreWarnings(['Warning: componentWillReceiveProps is deprecated']);

const roots = [];

function mountHelper(App) {
Expand Down

0 comments on commit 6b3ae64

Please sign in to comment.