mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 17:47:21 +08:00
Extract symbolicateStackTrace into its own module
Summary: Having a function that symbolicates any given stack trace is convenient, e.g. in #7459 More cleanup to follow. Reviewed By: davidaurelio Differential Revision: D3348616 fbshipit-source-id: 6313ec837869c6080829c811345a06aa1b2dcd21
This commit is contained in:
committed by
Facebook Github Bot 2
parent
7e100ac7a2
commit
2ef533352f
@@ -18,6 +18,7 @@ let exceptionID = 0;
|
||||
*/
|
||||
function reportException(e: Error, isFatal: bool) {
|
||||
const parseErrorStack = require('parseErrorStack');
|
||||
const symbolicateStackTrace = require('symbolicateStackTrace');
|
||||
const RCTExceptionsManager = require('NativeModules').ExceptionsManager;
|
||||
|
||||
const currentExceptionID = ++exceptionID;
|
||||
@@ -29,31 +30,16 @@ function reportException(e: Error, isFatal: bool) {
|
||||
RCTExceptionsManager.reportSoftException(e.message, stack, currentExceptionID);
|
||||
}
|
||||
if (__DEV__) {
|
||||
symbolicateAndUpdateStack(currentExceptionID, e.message, stack);
|
||||
symbolicateStackTrace(stack).then(
|
||||
(prettyStack) =>
|
||||
RCTExceptionsManager.updateExceptionMessage(e.message, prettyStack, currentExceptionID),
|
||||
(error) =>
|
||||
console.warn('Unable to symbolicate stack trace: ' + error.message)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function symbolicateAndUpdateStack(id, message, stack) {
|
||||
const getDevServer = require('getDevServer');
|
||||
const {fetch} = require('fetch');
|
||||
const {ExceptionsManager} = require('NativeModules');
|
||||
const devServer = getDevServer();
|
||||
if (!devServer.bundleLoadedFromServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(devServer.url + 'symbolicate', { method: 'POST', body: JSON.stringify({stack}) })
|
||||
.then(response => response.json())
|
||||
.then(response =>
|
||||
ExceptionsManager.updateExceptionMessage(message, response.stack, id))
|
||||
.catch(error => {
|
||||
// This can happen in a variety of normal situations, such as
|
||||
// Network module not being available, or when running locally
|
||||
console.warn('Unable to symbolicate stack trace: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs exceptions to the (native) console and displays them
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user