-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show more meaningful error stack in ReactNative redbox
Reviewed By: yungsters Differential Revision: D4797372 fbshipit-source-id: 069c013bcc3d58dd38a25979f4a04aed5fc1dde6
- Loading branch information
1 parent
7db16a4
commit d4aa42a
Showing
4 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Libraries/Renderer/src/renderers/native/ReactNativeFiberErrorDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactNativeFiberErrorDialog | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const ExceptionsManager = require('ExceptionsManager'); | ||
|
||
import type {CapturedError} from 'ReactFiberScheduler'; | ||
|
||
/** | ||
* Intercept lifecycle errors and ensure they are shown with the correct stack | ||
* trace within the native redbox component. | ||
*/ | ||
function ReactNativeFiberErrorDialog(capturedError: CapturedError): boolean { | ||
const {componentStack, error} = capturedError; | ||
|
||
let errorMessage: string; | ||
let errorStack: string; | ||
let errorType: Class<Error>; | ||
|
||
// Typically Errors are thrown but eg strings or null can be thrown as well. | ||
if (error && typeof error === 'object') { | ||
const {message, name} = error; | ||
|
||
const summary = message ? `${name}: ${message}` : name; | ||
|
||
errorMessage = `${summary}\n\nThis error is located at:${componentStack}`; | ||
errorStack = error.stack; | ||
errorType = error.constructor; | ||
} else { | ||
errorMessage = `Unspecified error at:${componentStack}`; | ||
errorStack = ''; | ||
errorType = Error; | ||
} | ||
|
||
const newError = new errorType(errorMessage); | ||
newError.stack = errorStack; | ||
|
||
ExceptionsManager.handleException(newError, false); | ||
|
||
// Return false here to prevent ReactFiberErrorLogger default behavior of | ||
// logging error details to console.error. Calls to console.error are | ||
// automatically routed to the native redbox controller, which we've already | ||
// done above by calling ExceptionsManager. | ||
return false; | ||
} | ||
|
||
module.exports.showDialog = ReactNativeFiberErrorDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters