GeezerVison is showing github.com — Print the error in DEV with addendum · react/react@aae244d
File treeExpand file treeCollapse file tree Open diff view settings use-sync-external-store/src/__tests__
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMConsoleErrorReporting-test.js +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -130,10 +130,17 @@ describe('ReactDOMConsoleErrorReporting', () => { | 130 | 130 | expect(windowOnError.mock.calls).toEqual([]); | 131 | 131 | expect(console.error.mock.calls).toEqual([ | 132 | 132 | [ | | 133 | + // Formatting | | 134 | + expect.stringContaining('%o'), | | 135 | + expect.objectContaining({ | | 136 | + message: 'Boom', | | 137 | + }), | 133 | 138 | // Addendum by React: | 134 | 139 | expect.stringContaining( | 135 | 140 | 'The above error occurred in the <Foo> component', | 136 | 141 | ), | | 142 | + expect.stringContaining('Foo'), | | 143 | + expect.stringContaining('Consider adding an error boundary'), | 137 | 144 | ], | 138 | 145 | ]); | 139 | 146 | } else { | @@ -183,10 +190,17 @@ describe('ReactDOMConsoleErrorReporting', () => { | 183 | 190 | expect(windowOnError.mock.calls).toEqual([]); | 184 | 191 | expect(console.error.mock.calls).toEqual([ | 185 | 192 | [ | | 193 | + // Formatting | | 194 | + expect.stringContaining('%o'), | | 195 | + expect.objectContaining({ | | 196 | + message: 'Boom', | | 197 | + }), | 186 | 198 | // Addendum by React: | 187 | 199 | expect.stringContaining( | 188 | 200 | 'The above error occurred in the <Foo> component', | 189 | 201 | ), | | 202 | + expect.stringContaining('Foo'), | | 203 | + expect.stringContaining('ErrorBoundary'), | 190 | 204 | ], | 191 | 205 | ]); | 192 | 206 | } else { | @@ -236,10 +250,17 @@ describe('ReactDOMConsoleErrorReporting', () => { | 236 | 250 | expect(windowOnError.mock.calls).toEqual([]); | 237 | 251 | expect(console.error.mock.calls).toEqual([ | 238 | 252 | [ | | 253 | + // Formatting | | 254 | + expect.stringContaining('%o'), | | 255 | + expect.objectContaining({ | | 256 | + message: 'Boom', | | 257 | + }), | 239 | 258 | // Addendum by React: | 240 | 259 | expect.stringContaining( | 241 | 260 | 'The above error occurred in the <Foo> component', | 242 | 261 | ), | | 262 | + expect.stringContaining('Foo'), | | 263 | + expect.stringContaining('Consider adding an error boundary'), | 243 | 264 | ], | 244 | 265 | ]); | 245 | 266 | } else { | @@ -292,10 +313,17 @@ describe('ReactDOMConsoleErrorReporting', () => { | 292 | 313 | expect(windowOnError.mock.calls).toEqual([]); | 293 | 314 | expect(console.error.mock.calls).toEqual([ | 294 | 315 | [ | | 316 | + // Formatting | | 317 | + expect.stringContaining('%o'), | | 318 | + expect.objectContaining({ | | 319 | + message: 'Boom', | | 320 | + }), | 295 | 321 | // Addendum by React: | 296 | 322 | expect.stringContaining( | 297 | 323 | 'The above error occurred in the <Foo> component', | 298 | 324 | ), | | 325 | + expect.stringContaining('Foo'), | | 326 | + expect.stringContaining('ErrorBoundary'), | 299 | 327 | ], | 300 | 328 | ]); | 301 | 329 | } else { | @@ -345,10 +373,17 @@ describe('ReactDOMConsoleErrorReporting', () => { | 345 | 373 | expect(windowOnError.mock.calls).toEqual([]); | 346 | 374 | expect(console.error.mock.calls).toEqual([ | 347 | 375 | [ | | 376 | + // Formatting | | 377 | + expect.stringContaining('%o'), | | 378 | + expect.objectContaining({ | | 379 | + message: 'Boom', | | 380 | + }), | 348 | 381 | // Addendum by React: | 349 | 382 | expect.stringContaining( | 350 | 383 | 'The above error occurred in the <Foo> component', | 351 | 384 | ), | | 385 | + expect.stringContaining('Foo'), | | 386 | + expect.stringContaining('Consider adding an error boundary'), | 352 | 387 | ], | 353 | 388 | ]); | 354 | 389 | } else { | @@ -401,10 +436,17 @@ describe('ReactDOMConsoleErrorReporting', () => { | 401 | 436 | expect(windowOnError.mock.calls).toEqual([]); | 402 | 437 | expect(console.error.mock.calls).toEqual([ | 403 | 438 | [ | | 439 | + // Formatting | | 440 | + expect.stringContaining('%o'), | | 441 | + expect.objectContaining({ | | 442 | + message: 'Boom', | | 443 | + }), | 404 | 444 | // Addendum by React: | 405 | 445 | expect.stringContaining( | 406 | 446 | 'The above error occurred in the <Foo> component', | 407 | 447 | ), | | 448 | + expect.stringContaining('Foo'), | | 449 | + expect.stringContaining('ErrorBoundary'), | 408 | 450 | ], | 409 | 451 | ]); | 410 | 452 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMConsoleErrorReportingLegacy-test.js +42-5Lines changed: 42 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -159,10 +159,17 @@ describe('ReactDOMConsoleErrorReporting', () => { | 159 | 159 | expect(console.error.mock.calls).toEqual([ | 160 | 160 | [expect.stringContaining('ReactDOM.render is no longer supported')], | 161 | 161 | [ | | 162 | + // Formatting | | 163 | + expect.stringContaining('%o'), | | 164 | + expect.objectContaining({ | | 165 | + message: 'Boom', | | 166 | + }), | 162 | 167 | // Addendum by React: | 163 | 168 | expect.stringContaining( | 164 | 169 | 'The above error occurred in the <Foo> component', | 165 | 170 | ), | | 171 | + expect.stringContaining('Foo'), | | 172 | + expect.stringContaining('Consider adding an error boundary'), | 166 | 173 | ], | 167 | 174 | ]); | 168 | 175 | } else { | @@ -215,12 +222,18 @@ describe('ReactDOMConsoleErrorReporting', () => { | 215 | 222 | expect(windowOnError.mock.calls).toEqual([]); | 216 | 223 | expect(console.error.mock.calls).toEqual([ | 217 | 224 | [expect.stringContaining('ReactDOM.render is no longer supported')], | 218 | | - // TODO: There is no log for this error now. | 219 | 225 | [ | | 226 | + // Formatting | | 227 | + expect.stringContaining('%o'), | | 228 | + expect.objectContaining({ | | 229 | + message: 'Boom', | | 230 | + }), | 220 | 231 | // Addendum by React: | 221 | 232 | expect.stringContaining( | 222 | 233 | 'The above error occurred in the <Foo> component', | 223 | 234 | ), | | 235 | + expect.stringContaining('Foo'), | | 236 | + expect.stringContaining('ErrorBoundary'), | 224 | 237 | ], | 225 | 238 | ]); | 226 | 239 | } else { | @@ -271,12 +284,18 @@ describe('ReactDOMConsoleErrorReporting', () => { | 271 | 284 | expect(windowOnError.mock.calls).toEqual([]); | 272 | 285 | expect(console.error.mock.calls).toEqual([ | 273 | 286 | [expect.stringContaining('ReactDOM.render is no longer supported')], | 274 | | - // TODO: There should be an error reported here. | 275 | 287 | [ | | 288 | + // Formatting | | 289 | + expect.stringContaining('%o'), | | 290 | + expect.objectContaining({ | | 291 | + message: 'Boom', | | 292 | + }), | 276 | 293 | // Addendum by React: | 277 | 294 | expect.stringContaining( | 278 | 295 | 'The above error occurred in the <Foo> component', | 279 | 296 | ), | | 297 | + expect.stringContaining('Foo'), | | 298 | + expect.stringContaining('Consider adding an error boundary'), | 280 | 299 | ], | 281 | 300 | ]); | 282 | 301 | } else { | @@ -332,12 +351,18 @@ describe('ReactDOMConsoleErrorReporting', () => { | 332 | 351 | expect(windowOnError.mock.calls).toEqual([]); | 333 | 352 | expect(console.error.mock.calls).toEqual([ | 334 | 353 | [expect.stringContaining('ReactDOM.render is no longer supported')], | 335 | | - // TODO: There should be a log here. | 336 | 354 | [ | | 355 | + // Formatting | | 356 | + expect.stringContaining('%o'), | | 357 | + expect.objectContaining({ | | 358 | + message: 'Boom', | | 359 | + }), | 337 | 360 | // Addendum by React: | 338 | 361 | expect.stringContaining( | 339 | 362 | 'The above error occurred in the <Foo> component', | 340 | 363 | ), | | 364 | + expect.stringContaining('Foo'), | | 365 | + expect.stringContaining('ErrorBoundary'), | 341 | 366 | ], | 342 | 367 | ]); | 343 | 368 | } else { | @@ -389,12 +414,18 @@ describe('ReactDOMConsoleErrorReporting', () => { | 389 | 414 | expect(windowOnError.mock.calls).toEqual([]); | 390 | 415 | expect(console.error.mock.calls).toEqual([ | 391 | 416 | [expect.stringContaining('ReactDOM.render is no longer supported')], | 392 | | - // TODO: We should have logged an error. | 393 | 417 | [ | | 418 | + // Formatting | | 419 | + expect.stringContaining('%o'), | | 420 | + expect.objectContaining({ | | 421 | + message: 'Boom', | | 422 | + }), | 394 | 423 | // Addendum by React: | 395 | 424 | expect.stringContaining( | 396 | 425 | 'The above error occurred in the <Foo> component', | 397 | 426 | ), | | 427 | + expect.stringContaining('Foo'), | | 428 | + expect.stringContaining('Consider adding an error boundary'), | 398 | 429 | ], | 399 | 430 | ]); | 400 | 431 | } else { | @@ -450,12 +481,18 @@ describe('ReactDOMConsoleErrorReporting', () => { | 450 | 481 | expect(windowOnError.mock.calls).toEqual([]); | 451 | 482 | expect(console.error.mock.calls).toEqual([ | 452 | 483 | [expect.stringContaining('ReactDOM.render is no longer supported')], | 453 | | - // TODO: There should be a log here. | 454 | 484 | [ | | 485 | + // Formatting | | 486 | + expect.stringContaining('%o'), | | 487 | + expect.objectContaining({ | | 488 | + message: 'Boom', | | 489 | + }), | 455 | 490 | // Addendum by React: | 456 | 491 | expect.stringContaining( | 457 | 492 | 'The above error occurred in the <Foo> component', | 458 | 493 | ), | | 494 | + expect.stringContaining('Foo'), | | 495 | + expect.stringContaining('ErrorBoundary'), | 459 | 496 | ], | 460 | 497 | ]); | 461 | 498 | } else { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -707,7 +707,7 @@ describe('ReactErrorBoundaries', () => { | 707 | 707 | }); | 708 | 708 | if (__DEV__) { | 709 | 709 | expect(console.error).toHaveBeenCalledTimes(1); | 710 | | - expect(console.error.mock.calls[0][0]).toContain( | | 710 | + expect(console.error.mock.calls[0][2]).toContain( | 711 | 711 | 'The above error occurred in the <BrokenRender> component:', | 712 | 712 | ); | 713 | 713 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactLegacyErrorBoundaries-test.internal.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -686,7 +686,7 @@ describe('ReactLegacyErrorBoundaries', () => { | 686 | 686 | expect(console.error.mock.calls[0][0]).toContain( | 687 | 687 | 'ReactDOM.render is no longer supported', | 688 | 688 | ); | 689 | | - expect(console.error.mock.calls[1][0]).toContain( | | 689 | + expect(console.error.mock.calls[1][2]).toContain( | 690 | 690 | 'The above error occurred in the <BrokenRender> component:', | 691 | 691 | ); | 692 | 692 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.js -15Lines changed: 0 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -243,21 +243,6 @@ function shouldProfile(current: Fiber): boolean { | 243 | 243 | ); | 244 | 244 | } | 245 | 245 |
| 246 | | -export function reportUncaughtErrorInDEV(error: mixed) { | 247 | | - // Wrapping each small part of the commit phase into a guarded | 248 | | - // callback is a bit too slow (https://github.com/facebook/react/pull/21666). | 249 | | - // But we rely on it to surface errors to DEV tools like overlays | 250 | | - // (https://github.com/facebook/react/issues/21712). | 251 | | - // As a compromise, rethrow only caught errors in a guard. | 252 | | - if (__DEV__) { | 253 | | - // TODO: This trick no longer works. Should probably use reportError maybe. | 254 | | - // invokeGuardedCallback(null, () => { | 255 | | - // throw error; | 256 | | - // }); | 257 | | - // clearCaughtError(); | 258 | | - } | 259 | | -} | 260 | | - | 261 | 246 | function callComponentWillUnmountWithTimer(current: Fiber, instance: any) { | 262 | 247 | instance.props = current.memoizedProps; | 263 | 248 | instance.state = current.memoizedState; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberErrorLogger.js +12-29Lines changed: 12 additions & 29 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,6 @@ import type {Fiber} from './ReactInternalTypes'; | 11 | 11 | import type {CapturedValue} from './ReactCapturedValue'; | 12 | 12 |
| 13 | 13 | import {showErrorDialog} from './ReactFiberErrorDialog'; | 14 | | -import {ClassComponent} from './ReactWorkTags'; | 15 | 14 | import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber'; | 16 | 15 | import {HostRoot} from 'react-reconciler/src/ReactWorkTags'; | 17 | 16 |
| @@ -33,25 +32,8 @@ export function logCapturedError( | 33 | 32 | const source = errorInfo.source; | 34 | 33 | const stack = errorInfo.stack; | 35 | 34 | const componentStack = stack !== null ? stack : ''; | 36 | | - // Browsers support silencing uncaught errors by calling | 37 | | - // `preventDefault()` in window `error` handler. | 38 | | - // We record this information as an expando on the error. | 39 | | - // TODO: We no longer track this. | 40 | | - if (error != null && error._suppressLogging) { | 41 | | - if (boundary.tag === ClassComponent) { | 42 | | - // The error is recoverable and was silenced. | 43 | | - // Ignore it and don't print the stack addendum. | 44 | | - // This is handy for testing error boundaries without noise. | 45 | | - return; | 46 | | - } | 47 | | - // The error is fatal. Since the silencing might have | 48 | | - // been accidental, we'll surface it anyway. | 49 | | - // However, the browser would have silenced the original error | 50 | | - // so we'll print it first, and then print the stack addendum. | 51 | | - console['error'](error); // Don't transform to our wrapper | 52 | | - // For a more detailed description of this block, see: | 53 | | - // https://github.com/facebook/react/pull/13384 | 54 | | - } | | 35 | + // TODO: There's no longer a way to silence these warnings e.g. for tests. | | 36 | + // See https://github.com/facebook/react/pull/13384 | 55 | 37 |
| 56 | 38 | const componentName = source ? getComponentNameFromFiber(source) : null; | 57 | 39 | const componentNameMessage = componentName | @@ -70,16 +52,17 @@ export function logCapturedError( | 70 | 52 | `React will try to recreate this component tree from scratch ` + | 71 | 53 | `using the error boundary you provided, ${errorBoundaryName}.`; | 72 | 54 | } | 73 | | - const combinedMessage = | 74 | | - `${componentNameMessage}\n${componentStack}\n\n` + | 75 | | - `${errorBoundaryMessage}`; | 76 | 55 |
| 77 | | - // TODO: The error is no longer printed by the browser. | 78 | | - // In development, we provide our own message with just the component stack. | 79 | | - // We don't include the original error message and JS stack because the browser | 80 | | - // has already printed it. Even if the application swallows the error, it is still | 81 | | - // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils. | 82 | | - console['error'](combinedMessage); // Don't transform to our wrapper | | 56 | + // In development, we provide our own message which includes the component stack | | 57 | + // in addition to the error. | | 58 | + console['error']( | | 59 | + // Don't transform to our wrapper | | 60 | + '%o\n\n%s\n%s\n\n%s', | | 61 | + error, | | 62 | + componentNameMessage, | | 63 | + componentStack, | | 64 | + errorBoundaryMessage, | | 65 | + ); | 83 | 66 | } else { | 84 | 67 | // In production, we print the error directly. | 85 | 68 | // This will include the message, the JS stack, and anything the browser wants to show. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -186,7 +186,6 @@ import { | 186 | 186 | reconnectPassiveEffects, | 187 | 187 | reappearLayoutEffects, | 188 | 188 | disconnectPassiveEffect, | 189 | | - reportUncaughtErrorInDEV, | 190 | 189 | invokeLayoutEffectMountInDEV, | 191 | 190 | invokePassiveEffectMountInDEV, | 192 | 191 | invokeLayoutEffectUnmountInDEV, | @@ -3384,7 +3383,6 @@ export function captureCommitPhaseError( | 3384 | 3383 | error: mixed, | 3385 | 3384 | ) { | 3386 | 3385 | if (__DEV__) { | 3387 | | - reportUncaughtErrorInDEV(error); | 3388 | 3386 | setIsRunningInsertionEffect(false); | 3389 | 3387 | } | 3390 | 3388 | if (sourceFiber.tag === HostRoot) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1510,7 +1510,8 @@ describe('ReactIncrementalErrorHandling', () => { | 1510 | 1510 |
| 1511 | 1511 | if (__DEV__) { | 1512 | 1512 | expect(console.error).toHaveBeenCalledTimes(1); | 1513 | | - expect(console.error.mock.calls[0][0]).toContain( | | 1513 | + expect(console.error.mock.calls[0][1]).toBe(notAnError); | | 1514 | + expect(console.error.mock.calls[0][2]).toContain( | 1514 | 1515 | 'The above error occurred in the <BadRender> component:', | 1515 | 1516 | ); | 1516 | 1517 | } else { | @@ -1911,7 +1912,7 @@ describe('ReactIncrementalErrorHandling', () => { | 1911 | 1912 | expect(console.error.mock.calls[0][0]).toContain( | 1912 | 1913 | 'Cannot update a component (`%s`) while rendering a different component', | 1913 | 1914 | ); | 1914 | | - expect(console.error.mock.calls[1][0]).toContain( | | 1915 | + expect(console.error.mock.calls[1][2]).toContain( | 1915 | 1916 | 'The above error occurred in the <App> component', | 1916 | 1917 | ); | 1917 | 1918 | } | |
|