From 5818935a321c7fcf152848a6e8617dbc31ed6dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 7 Apr 2017 14:35:49 +0300 Subject: [PATCH] Address file import bugs I don't know why why, but wbp.saveDocument() destroys the document object which is passed into it. This means that further access of the document is impossible and raises errors, which we were not handling properly and not returning on attachment saving. I've added error handling and changed removed code which tries to access the document after the Zotero.Utilities.Internal.saveDocument() call. Addresses https://forums.zotero.org/discussion/64745/5-0-beta-apparently-stuck-at-saving-to --- chrome/content/zotero/xpcom/attachments.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 0f0fab07fe..5a28e7f209 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -277,8 +277,14 @@ Zotero.Attachments = new function(){ saveOptions }) .then(function (attachmentItem) { - Zotero.Browser.deleteHiddenBrowser(browser); deferred.resolve(attachmentItem); + }) + .catch(function(e) { + Zotero.logError(e); + deferred.reject(); + }) + .finally(function() { + Zotero.Browser.deleteHiddenBrowser(browser); }); }, undefined, @@ -586,7 +592,7 @@ Zotero.Attachments = new function(){ } if (contentType === 'text/html' || contentType === 'application/xhtml+xml') { - Zotero.debug('Saving document with saveURI()'); + Zotero.debug('Saving document with saveDocument()'); yield Zotero.Utilities.Internal.saveDocument(document, tmpFile.path); } else { @@ -670,9 +676,10 @@ Zotero.Attachments = new function(){ }, 1000); } else if (Zotero.MIME.isTextType(contentType)) { - // Index document immediately, so that browser object can't - // be removed before indexing completes - yield Zotero.Fulltext.indexDocument(document, attachmentItem.id); + // wbp.saveDocument consumes the document context (in Zotero.Utilities.Internal.saveDocument) + // Seems like a mozilla bug, but nothing on bugtracker. + // Either way, we don't rely on Zotero.Fulltext.indexDocument here anymore + yield Zotero.Fulltext.indexItems(attachmentItem.id, true, true); } return attachmentItem;