From ae3a834b4c05d978083db7d19ca9674ede251dcb Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 7 Dec 2015 13:42:19 -0800 Subject: [PATCH] Log global errors Use the global error handler, window.onerror, to catch miscellaneous exceptions and pipe them into the debug log. Fixes #456 // FREEBIE --- js/debugLog.js | 4 ++++ js/index.js | 35 +++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/js/debugLog.js b/js/debugLog.js index 9ae4b0b12f..57ec4504e3 100644 --- a/js/debugLog.js +++ b/js/debugLog.js @@ -33,5 +33,9 @@ }).fail(resolve); }); }; + + window.onerror = function(message, script, line, col, error) { + console.log(error); + }; } })(); diff --git a/js/index.js b/js/index.js index f4dc54ba4b..18d7b1ab9b 100644 --- a/js/index.js +++ b/js/index.js @@ -5,21 +5,36 @@ (function () { 'use strict'; + function logError(error) { + extension.windows.getBackground(function(bg) { + bg.console.log('index.html: ', error); + }); + } + + window.onerror = function(message, script, line, col, error) { + logError(error); + }; + var view; function render() { extension.windows.getBackground(function(bg) { extension.windows.getCurrent(function(appWindow) { - if (view) { view.remove(); } - var $body = bg.$('body',document).empty(); - view = new bg.Whisper.InboxView({appWindow: appWindow}); - view.$el.prependTo($body); - window.openConversation = function(conversation) { - if (conversation) { - view.openConversation(null, conversation); - } - }; - openConversation(bg.getOpenConversation()); + try { + if (view) { view.remove(); } + var $body = bg.$('body',document).empty(); + view = new bg.Whisper.InboxView({appWindow: appWindow}); + view.$el.prependTo($body); + window.openConversation = function(conversation) { + if (conversation) { + view.openConversation(null, conversation); + } + }; + openConversation(bg.getOpenConversation()); + } catch (e) { + logError(e); + } + }); }); }