diff --git a/packages/logging/logging_cordova.js b/packages/logging/logging_cordova.js new file mode 100644 index 0000000000..56f52ceba8 --- /dev/null +++ b/packages/logging/logging_cordova.js @@ -0,0 +1,12 @@ +// Log all uncaught errors so they can be printed to the developer. +// But since Android's adb catlog already prints the uncaught exceptions, we +// can disable it for Android. +if (! /Android/i.test(navigator.userAgent)) { + window.onerror = function (msg, url, line) { + // Cut off the url prefix, the meaningful part always starts at 'www/' in + // Cordova apps. + url = url.replace(/^.*?\/www\//, ''); + console.log('Uncaught Error: ' + msg + ':' + line + ':' + url); + }; +} + diff --git a/packages/logging/package.js b/packages/logging/package.js index c3d3153b25..f3e6942c83 100644 --- a/packages/logging/package.js +++ b/packages/logging/package.js @@ -15,6 +15,7 @@ Package.on_use(function (api) { api.export('Log'); api.use(['underscore', 'ejson']); api.add_files('logging.js'); + api.add_files('logging_cordova.js', 'client.cordova'); }); Package.on_test(function (api) { diff --git a/tools/commands-cordova.js b/tools/commands-cordova.js index 59153939dd..c4828d384d 100644 --- a/tools/commands-cordova.js +++ b/tools/commands-cordova.js @@ -405,7 +405,7 @@ var execCordovaOnPlatform = function (localPath, platformName) { // remove a part of file url we don't like line = line.replace(/^file:\/\/\/android_asset\/www\//, ''); // filename.js?hashsha1: Line 123 : message goes here - var parsedLine = line.match(/^([^?]+)\?[a-zA-Z0-9]+: Line (\d+) : (.*)$/); + var parsedLine = line.match(/^([^?]+)(\?[a-zA-Z0-9]+)?: Line (\d+) : (.*)$/); if (! parsedLine) return Log.format(Log.objFromText(line), { color: true }); @@ -414,8 +414,8 @@ var execCordovaOnPlatform = function (localPath, platformName) { time: new Date, level: 'info', file: parsedLine[1], - line: parsedLine[2], - message: parsedLine[3], + line: parsedLine[3], + message: parsedLine[4], program: 'android' }; return Log.format(output, {