From 946ec48a07c8f205c8ea09f466dd5c89659eeec3 Mon Sep 17 00:00:00 2001 From: Alex Kotliarskyi Date: Fri, 20 May 2016 12:13:02 -0700 Subject: [PATCH] Use RN Packager to symbolicate stack in redbox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Initialization/ExceptionsManager.js | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js b/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js index a75b166e2..19d651336 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js +++ b/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js @@ -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 */