From 8e25a4bdf3ac873b7e821d52b9ab89425805825e Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Tue, 10 Feb 2015 20:49:16 -0600 Subject: [PATCH 1/2] Handle XPCOM Exceptions in varDump --- chrome/content/zotero/xpcom/utilities.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 5b67eb1b1..ab9de990e 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1217,9 +1217,10 @@ Zotero.Utilities = { level_padding += " "; } - //Special handling for Error + //Special handling for Error or Exception + var isException = Zotero.isFx && !Zotero.isBookmarklet && obj instanceof Components.interfaces.nsIException; var isError = obj instanceof Error; - if (!isError && obj.constructor) { + if (!isException && !isError && obj.constructor && obj.stack) { switch (obj.constructor.name) { case 'Error': case 'EvalError': @@ -1231,8 +1232,16 @@ Zotero.Utilities = { isError = true; } } - if (isError) { - return (obj.constructor.name ? obj.constructor.name : 'Error') + ': ' + + if (isError || isException) { + var header = ''; + if (isError) { + header = obj.constructor.name ? obj.constructor.name : 'Error'; + } else { + header = obj.name ? obj.name + ' ' : '') + 'Exception'; + } + + return header + ': ' + (obj.message ? ('' + obj.message).replace(/^/gm, level_padding).trim() : '') + '\n' + level_padding + "===== Stack Trace =====\n" + (obj.stack ? obj.stack.trim().replace(/^(?=.)/gm, level_padding) : '') From cae9a89b9d9ceea2bd22b6eb62b6e8285781aa9a Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Tue, 10 Feb 2015 21:26:50 -0600 Subject: [PATCH 2/2] Fix syntax error in varDump --- chrome/content/zotero/xpcom/utilities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index ab9de990e..bf774cd08 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1238,7 +1238,7 @@ Zotero.Utilities = { if (isError) { header = obj.constructor.name ? obj.constructor.name : 'Error'; } else { - header = obj.name ? obj.name + ' ' : '') + 'Exception'; + header = (obj.name ? obj.name + ' ' : '') + 'Exception'; } return header + ': '