From 4cbf255a53e83b781d22280b3ce465c36c8fc557 Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Mon, 11 Aug 2014 21:08:32 -0700 Subject: [PATCH 1/2] Logging uncaught errors --- packages/logging/logging_cordova.js | 9 +++++++++ packages/logging/package.js | 1 + 2 files changed, 10 insertions(+) create mode 100644 packages/logging/logging_cordova.js diff --git a/packages/logging/logging_cordova.js b/packages/logging/logging_cordova.js new file mode 100644 index 0000000000..e8465b1f9d --- /dev/null +++ b/packages/logging/logging_cordova.js @@ -0,0 +1,9 @@ +// Log all uncaught errors so they can be printed to the developer through adb +// and logcat with Android or regular log file with iOS. +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) { From 64472ce8951d6a9e1b0df382190a5f6e7986adff Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Mon, 11 Aug 2014 21:24:12 -0700 Subject: [PATCH 2/2] Fix error reporting and logging on Android in production mode --- packages/logging/logging_cordova.js | 17 ++++++++++------- tools/commands-cordova.js | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/logging/logging_cordova.js b/packages/logging/logging_cordova.js index e8465b1f9d..56f52ceba8 100644 --- a/packages/logging/logging_cordova.js +++ b/packages/logging/logging_cordova.js @@ -1,9 +1,12 @@ -// Log all uncaught errors so they can be printed to the developer through adb -// and logcat with Android or regular log file with iOS. -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); +// 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/tools/commands-cordova.js b/tools/commands-cordova.js index 93bfd06a28..f2c9d966c3 100644 --- a/tools/commands-cordova.js +++ b/tools/commands-cordova.js @@ -402,7 +402,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 }); @@ -411,8 +411,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, {