From b8ad18e96d53f3fe692059f066a308ef5defab63 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 25 Jun 2021 06:39:48 -0400 Subject: [PATCH] Fix broken detection after error loading a translator's code The bug fixed in bde9a74f9d was triggering an error getting code for a deleted search translator, which due to this bug caused a double complete() call that got detection all out of sync, which caused some search translators to be skipped, which resulted in ISBN lookup failures. --- .../zotero/xpcom/translation/translate.js | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index a30f61394d..26cc063985 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1754,9 +1754,9 @@ Zotero.Translate.Base.prototype = { /** * Loads the translator into its sandbox * @param {Zotero.Translator} translator - * @return {Promise} Whether the translator could be successfully loaded + * @return {Promise} */ - "_loadTranslator": Zotero.Promise.method(function (translator) { + _loadTranslator: async function (translator) { var sandboxLocation = this._getSandboxLocation(); if(!this._sandboxLocation || sandboxLocation !== this._sandboxLocation) { this._sandboxLocation = sandboxLocation; @@ -1798,25 +1798,17 @@ Zotero.Translate.Base.prototype = { }.bind(this); if (this.noWait) { - try { - let codePromise = translator.getCode(); - if (!codePromise.isResolved()) { - throw new Error("Code promise is not resolved in noWait mode"); - } - parse(codePromise.value()); - } - catch (e) { - this.complete(false, e); + let codePromise = translator.getCode(); + if (!codePromise.isResolved()) { + throw new Error("Code promise is not resolved in noWait mode"); } + parse(codePromise.value()); } else { - return translator.getCode() - .then(parse) - .catch(function(e) { - this.complete(false, e); - }.bind(this)); + let code = await translator.getCode(); + await parse(code); } - }), + }, /** * Generates a sandbox for scraping/scraper detection