Use RN Packager to symbolicate stack in redbox

Summary:
See "D3291793 Symbolicate JS stacktrace using RN Packager" for the background
of why this matters. TLDR - saving tons of memory by moving symbolication from
JSC into server and cleaning up old hacks.

Before this change: a redbox causes +73MB JSC size
{F60869250}
{F60869249}

After this change: a redbox causes +1MB JSC size
{F61005061}
{F61005062}

Next step – replace JS implementation by native to show better progress and
clean up even more old APIs (ExceptionsManager.updateExceptionMessage).

Reviewed By: davidaurelio

Differential Revision: D3319151

fbshipit-source-id: 48ff4df27642ea4e1bc2414f48a8dd4d32adee50
This commit is contained in:
Alex Kotliarskyi 2016-05-20 12:13:02 -07:00 коммит произвёл Facebook Github Bot 8
Родитель 62e74f3832
Коммит 946ec48a07
1 изменённых файлов: 18 добавлений и 13 удалений

Просмотреть файл

@ -29,23 +29,28 @@ function reportException(e: Error, isFatal: bool) {
RCTExceptionsManager.reportSoftException(e.message, stack, currentExceptionID);
}
if (__DEV__) {
require('SourceMapsCache').getSourceMaps().then(sourceMaps => {
const prettyStack = parseErrorStack(e, sourceMaps);
RCTExceptionsManager.updateExceptionMessage(
e.message,
prettyStack,
currentExceptionID,
);
})
.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 load source map: ' + error.message);
});
symbolicateAndUpdateStack(currentExceptionID, e.message, stack);
}
}
}
function symbolicateAndUpdateStack(id, message, stack) {
const {fetch} = require('fetch');
const {SourceCode, ExceptionsManager} = require('NativeModules');
const match = SourceCode.scriptURL && SourceCode.scriptURL.match(/^https?:\/\/.*?\//);
const endpoint = (match && match[0] : 'http://localhost:8081/') + 'symbolicate';
fetch(endpoint, { 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
*/