Skip to content

Commit 5ab4184

Browse files
yungstersmeta-codesync[bot]
authored andcommitted
RN: Remove Special Case for "Warning: " Errors (#55193)
Summary: Pull Request resolved: #55193 React no longer emits the "Warning: " prefix from error messages, so we no longer need special handling for error messages with this prefix. If third party call sites are depending on `console.error('Warning: …')` being treated as a warning, they should be migrated to use `console.warn('…')`. Changelog: [General][Changed] - Logs created by `console.error` that begin with "Warning: " will no longer be treated as warnings. These call sites should migrate to using `console.warn` instead. Reviewed By: javache, robhogan Differential Revision: D90795590 fbshipit-source-id: 1b51ab63fd02cead4da33c64040c88aac50abbfb
1 parent f7cd8c4 commit 5ab4184

5 files changed

Lines changed: 3 additions & 193 deletions

File tree

packages/react-native/Libraries/LogBox/LogBox.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ if (__DEV__) {
148148
let format = args[0];
149149
if (typeof format === 'string') {
150150
const filterResult =
151-
require('../LogBox/Data/LogBoxData').checkWarningFilter(
152-
// For legacy reasons, we strip the warning prefix from the message.
153-
// Can remove this once we remove the warning module altogether.
154-
format.replace(/^Warning: /, ''),
155-
);
151+
require('../LogBox/Data/LogBoxData').checkWarningFilter(format);
156152
if (filterResult.monitorEvent !== 'warning_unhandled') {
157153
if (filterResult.suppressCompletely) {
158154
return;

packages/react-native/Libraries/LogBox/UI/LogBoxMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function TappableLinks(props: {
101101
}
102102

103103
const cleanContent = (content: string) =>
104-
content.replace(/^(TransformError |Warning: (Warning: )?|Error: )/g, '');
104+
content.replace(/^(TransformError |Error: )/g, '');
105105

106106
function LogBoxMessage(props: Props): React.Node {
107107
const {content, substitutions}: Message = props.message;

packages/react-native/Libraries/LogBox/UI/__tests__/LogBoxMessage-test.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -179,34 +179,6 @@ describe('LogBoxMessage', () => {
179179
expect(output).toMatchSnapshot();
180180
});
181181

182-
it('Should strip "Warning: " without breaking substitution', async () => {
183-
const output = await render.create(
184-
<LogBoxMessage
185-
style={{}}
186-
message={{
187-
content: 'Warning: normal substitution normal',
188-
substitutions: [{length: 12, offset: 16}],
189-
}}
190-
/>,
191-
);
192-
193-
expect(output).toMatchSnapshot();
194-
});
195-
196-
it('Should strip "Warning: Warning: " without breaking substitution', async () => {
197-
const output = await render.create(
198-
<LogBoxMessage
199-
style={{}}
200-
message={{
201-
content: 'Warning: Warning: normal substitution normal',
202-
substitutions: [{length: 12, offset: 25}],
203-
}}
204-
/>,
205-
);
206-
207-
expect(output).toMatchSnapshot();
208-
});
209-
210182
it('Should make links tappable', async () => {
211183
const output = await render.create(
212184
<LogBoxMessage

packages/react-native/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxMessage-test.js.snap

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,6 @@ Array [
7777
]
7878
`;
7979

80-
exports[`LogBoxMessage Should strip "Warning: " without breaking substitution 1`] = `
81-
Array [
82-
<Text>
83-
normal
84-
</Text>,
85-
<Text
86-
style={Object {}}
87-
>
88-
substitution
89-
</Text>,
90-
<Text>
91-
normal
92-
</Text>,
93-
]
94-
`;
95-
96-
exports[`LogBoxMessage Should strip "Warning: Warning: " without breaking substitution 1`] = `
97-
Array [
98-
<Text>
99-
normal
100-
</Text>,
101-
<Text
102-
style={Object {}}
103-
>
104-
substitution
105-
</Text>,
106-
<Text>
107-
normal
108-
</Text>,
109-
]
110-
`;
111-
11280
exports[`LogBoxMessage should render a plaintext message and clean the content 1`] = `
11381
<Text>
11482
This should not start with Error:

packages/react-native/Libraries/LogBox/__tests__/LogBox-test.js

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare var console: any;
1818

1919
function mockFilterResult(returnValues: $FlowFixMe) {
2020
(LogBoxData.checkWarningFilter: any).mockReturnValue({
21-
finalFormat: 'Warning: ...',
21+
finalFormat: '...',
2222
forceDialogImmediately: false,
2323
suppressDialog_LEGACY: false,
2424
suppressCompletely: false,
@@ -126,17 +126,6 @@ describe('LogBox', () => {
126126
expect(LogBoxData.reportLogBoxError).toBeCalledWith(mockError);
127127
});
128128

129-
it('only registers errors beginning with "Warning: "', () => {
130-
jest.spyOn(LogBoxData, 'addLog');
131-
jest.spyOn(LogBoxData, 'checkWarningFilter');
132-
133-
LogBox.install();
134-
135-
console.error('...');
136-
expect(LogBoxData.addLog).not.toBeCalled();
137-
expect(LogBoxData.checkWarningFilter).not.toBeCalled();
138-
});
139-
140129
it('registers react errors with the formatting from filter', () => {
141130
jest.spyOn(LogBoxData, 'addLog');
142131
jest.spyOn(LogBoxData, 'checkWarningFilter');
@@ -245,121 +234,6 @@ describe('LogBox', () => {
245234
);
246235
});
247236

248-
it('registers warning module errors with the formatting from filter', () => {
249-
jest.spyOn(LogBoxData, 'addLog');
250-
jest.spyOn(LogBoxData, 'checkWarningFilter');
251-
252-
mockFilterResult({
253-
finalFormat: 'Custom format',
254-
});
255-
256-
ExceptionsManager.installConsoleErrorReporter();
257-
LogBox.install();
258-
259-
console.error('Warning: ...');
260-
expect(LogBoxData.addLog).toBeCalledWith(
261-
expect.objectContaining({
262-
message: {content: 'Custom format', substitutions: []},
263-
category: 'Custom format',
264-
}),
265-
);
266-
expect(LogBoxData.checkWarningFilter).toBeCalledWith('...');
267-
});
268-
269-
it('registers warning module errors as errors by default', () => {
270-
jest.spyOn(LogBoxData, 'addLog');
271-
jest.spyOn(LogBoxData, 'checkWarningFilter');
272-
273-
mockFilterResult({});
274-
275-
ExceptionsManager.installConsoleErrorReporter();
276-
LogBox.install();
277-
278-
console.error('Warning: ...');
279-
expect(LogBoxData.addLog).toBeCalledWith(
280-
expect.objectContaining({level: 'error'}),
281-
);
282-
expect(LogBoxData.checkWarningFilter).toBeCalledWith('...');
283-
});
284-
285-
it('registers warning module errors with only legacy suppression as warning', () => {
286-
jest.spyOn(LogBoxData, 'addLog');
287-
jest.spyOn(LogBoxData, 'checkWarningFilter');
288-
289-
mockFilterResult({
290-
suppressDialog_LEGACY: true,
291-
monitorEvent: 'warning',
292-
});
293-
294-
ExceptionsManager.installConsoleErrorReporter();
295-
LogBox.install();
296-
297-
console.error('Warning: ...');
298-
expect(LogBoxData.addLog).toBeCalledWith(
299-
expect.objectContaining({level: 'warn'}),
300-
);
301-
});
302-
303-
it('registers warning module errors with a forced dialog as fatals', () => {
304-
jest.spyOn(LogBoxData, 'addLog');
305-
jest.spyOn(LogBoxData, 'checkWarningFilter');
306-
307-
mockFilterResult({
308-
forceDialogImmediately: true,
309-
monitorEvent: 'warning',
310-
});
311-
312-
ExceptionsManager.installConsoleErrorReporter();
313-
LogBox.install();
314-
315-
console.error('Warning: ...');
316-
expect(LogBoxData.addLog).toBeCalledWith(
317-
expect.objectContaining({level: 'fatal'}),
318-
);
319-
});
320-
321-
it('ignores warning module errors that are suppressed completely', () => {
322-
jest.spyOn(LogBoxData, 'addLog');
323-
jest.spyOn(LogBoxData, 'checkWarningFilter');
324-
325-
mockFilterResult({
326-
suppressCompletely: true,
327-
monitorEvent: 'warning',
328-
});
329-
330-
ExceptionsManager.installConsoleErrorReporter();
331-
LogBox.install();
332-
333-
console.error('Warning: ...');
334-
expect(LogBoxData.addLog).not.toBeCalled();
335-
});
336-
337-
it('ignores warning module errors that are pattern ignored', () => {
338-
jest.spyOn(LogBoxData, 'checkWarningFilter');
339-
jest.spyOn(LogBoxData, 'isMessageIgnored').mockReturnValue(true);
340-
jest.spyOn(LogBoxData, 'addLog');
341-
342-
mockFilterResult({});
343-
344-
LogBox.install();
345-
346-
console.error('Warning: ...');
347-
expect(LogBoxData.addLog).not.toBeCalled();
348-
});
349-
350-
it('ignores warning module errors that are from LogBox itself', () => {
351-
jest.spyOn(LogBoxData, 'checkWarningFilter');
352-
jest.spyOn(LogBoxData, 'isLogBoxErrorMessage').mockReturnValue(true);
353-
jest.spyOn(LogBoxData, 'addLog');
354-
355-
mockFilterResult({});
356-
357-
LogBox.install();
358-
359-
console.error('Warning: ...');
360-
expect(LogBoxData.addLog).not.toBeCalled();
361-
});
362-
363237
it('ignores logs that are pattern ignored"', () => {
364238
jest.spyOn(LogBoxData, 'checkWarningFilter');
365239
jest.spyOn(LogBoxData, 'isMessageIgnored').mockReturnValue(true);

0 commit comments

Comments
 (0)