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.
This commit is contained in:
Dan Stillman 2021-06-25 06:39:48 -04:00
parent bde9a74f9d
commit b8ad18e96d

View file

@ -1754,9 +1754,9 @@ Zotero.Translate.Base.prototype = {
/**
* Loads the translator into its sandbox
* @param {Zotero.Translator} translator
* @return {Promise<Boolean>} 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