diff --git a/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js b/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js index 91afe2008..224ce0966 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js +++ b/Libraries/JavaScriptAppEngine/Initialization/ExceptionsManager.js @@ -48,8 +48,10 @@ function reportException(e: Exception, isFatal: bool, stack?: any) { var prettyStack = parseErrorStack(e, map); RCTExceptionsManager.updateExceptionMessage(e.message, prettyStack); }) - .then(null, error => { - console.error('#CLOWNTOWN (error while displaying error): ' + error.message); + .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); }); } } diff --git a/Libraries/JavaScriptAppEngine/Initialization/loadSourceMap.js b/Libraries/JavaScriptAppEngine/Initialization/loadSourceMap.js index a826db7bf..c3499ac9f 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/loadSourceMap.js +++ b/Libraries/JavaScriptAppEngine/Initialization/loadSourceMap.js @@ -13,10 +13,13 @@ 'use strict'; var Promise = require('Promise'); -var RCTSourceCode = require('NativeModules').SourceCode; +var NativeModules = require('NativeModules'); var SourceMapConsumer = require('SourceMap').SourceMapConsumer; var SourceMapURL = require('./source-map-url'); +var RCTSourceCode = NativeModules.SourceCode; +var RCTDataManager = NativeModules.DataManager; + function loadSourceMap(): Promise { return fetchSourceMap() .then(map => new SourceMapConsumer(map)); @@ -31,17 +34,31 @@ function fetchSourceMap(): Promise { return Promise.reject(new Error('RCTSourceCode module is not available')); } + if (!RCTDataManager) { + // Used internally by fetch + return Promise.reject(new Error('RCTDataManager module is not available')); + } + return new Promise(RCTSourceCode.getScriptText) .then(extractSourceMapURL) + .then((url) => { + if (url === null) { + return Promise.reject(new Error('No source map URL found. May be running from bundled file.')); + } + return Promise.resolve(url); + }) .then(fetch) .then(response => response.text()) } -function extractSourceMapURL({url, text, fullSourceMappingURL}): string { +function extractSourceMapURL({url, text, fullSourceMappingURL}): ?string { if (fullSourceMappingURL) { return fullSourceMappingURL; } var mapURL = SourceMapURL.getFrom(text); + if (!mapURL) { + return null; + } var baseURL = url.match(/(.+:\/\/.*?)\//)[1]; return baseURL + mapURL; }