From 44da6924f9efd34a83c5cbcdf10f064ac7adcb38 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 30 Nov 2017 11:56:29 -0800 Subject: [PATCH] A variety of logging improvements to track down bugs (#1832) * Log when we get a blocked numbers sync message * Save three old signed keys in addition to the current active * Remove the mystery from all the error-related log messages * Log successful load of signed key - to help debug prekey errors * removeSignedPreKey: Don't hang or crash in error cases * Log on top-level unhandled promise rejection * Remove trailing comma in param list, Electron 1.6 does not like * Harden top-level error handler for strange object shapes --- js/background.js | 3 +-- js/libtextsecure.js | 3 ++- js/logging.js | 6 +++++- js/models/messages.js | 7 +++++-- js/signal_protocol_store.js | 16 +++++++++++++--- libtextsecure/account_manager.js | 2 +- libtextsecure/message_receiver.js | 1 + 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/js/background.js b/js/background.js index 36fb406e6c21..b0aa1268c251 100644 --- a/js/background.js +++ b/js/background.js @@ -559,8 +559,7 @@ function onError(ev) { var error = ev.error; - console.log(error); - console.log(error.stack); + console.log('background onError:', error && error.stack ? error.stack : error); if (error.name === 'HTTPError' && (error.code == 401 || error.code == 403)) { Whisper.Registration.remove(); diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 14980063a104..3ceec56c0d82 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38049,7 +38049,7 @@ var TextSecureServer = (function() { console.log("Old signed prekey record count: " + oldRecords.length); oldRecords.forEach(function(oldRecord) { - if ( oldRecord.keyId > activeSignedPreKeyId - 3 ) { + if ( oldRecord.keyId >= activeSignedPreKeyId - 3 ) { // keep at least the last 3 signed keys return; } @@ -39151,6 +39151,7 @@ MessageReceiver.prototype.extend({ }.bind(this)); }, handleBlocked: function(envelope, blocked) { + console.log('Setting these numbers as blocked:', blocked.numbers); textsecure.storage.put('blocked', blocked.numbers); }, isBlocked: function(number) { diff --git a/js/logging.js b/js/logging.js index f7a687fe0a4d..19f26699b236 100644 --- a/js/logging.js +++ b/js/logging.js @@ -161,6 +161,10 @@ window.log = { }; window.onerror = function(message, script, line, col, error) { - window.log.error(error.stack); + const errorInfo = error && error.stack ? error.stack : JSON.stringify(error); + window.log.error('Top-level unhandled error: ' + errorInfo); }; +window.addEventListener('unhandledrejection', function(rejectionEvent) { + window.log.error('Top-level unhandled promise rejection: ' + rejectionEvent.reason); +}); diff --git a/js/models/messages.js b/js/models/messages.js index 76732958c478..7f8d5ddfe63a 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -314,8 +314,11 @@ errors = [errors]; } errors.forEach(function(e) { - console.log(e); - console.log(e.reason, e.stack); + console.log( + 'Message.saveErrors:', + e && e.reason ? e.reason : null, + e && e.stack ? e.stack : e + ); }); errors = errors.map(function(e) { if (e.constructor === Error || diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index e3beac5b9ed7..a744a703f0d2 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -211,7 +211,16 @@ this.trigger('removePreKey'); return new Promise(function(resolve) { - prekey.destroy().then(function() { + var deferred = prekey.destroy(); + if (!deferred) { + return resolve(); + } + + return deferred.then(resolve, function(error) { + console.log( + 'removePreKey error:', + error && error.stack ? error.stack : error + ); resolve(); }); }); @@ -222,6 +231,7 @@ var prekey = new SignedPreKey({id: keyId}); return new Promise(function(resolve) { prekey.fetch().then(function() { + console.log('Successfully loaded prekey:', prekey.get('id')); resolve({ pubKey : prekey.get('publicKey'), privKey : prekey.get('privateKey'), @@ -229,14 +239,14 @@ keyId : prekey.get('id') }); }).fail(function() { - console.log("Failed to load signed prekey:", keyId); + console.log('Failed to load signed prekey:', keyId); resolve(); }); }); }, loadSignedPreKeys: function() { if (arguments.length > 0) { - return Promise.reject(new Error("loadSignedPreKeys takes no arguments")); + return Promise.reject(new Error('loadSignedPreKeys takes no arguments')); } var signedPreKeys = new SignedPreKeyCollection(); return new Promise(function(resolve) { diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index 45c904059f5c..320480915724 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -179,7 +179,7 @@ console.log("Old signed prekey record count: " + oldRecords.length); oldRecords.forEach(function(oldRecord) { - if ( oldRecord.keyId > activeSignedPreKeyId - 3 ) { + if ( oldRecord.keyId >= activeSignedPreKeyId - 3 ) { // keep at least the last 3 signed keys return; } diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 3d60f11c8923..62e88108718a 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -730,6 +730,7 @@ MessageReceiver.prototype.extend({ }.bind(this)); }, handleBlocked: function(envelope, blocked) { + console.log('Setting these numbers as blocked:', blocked.numbers); textsecure.storage.put('blocked', blocked.numbers); }, isBlocked: function(number) {