Don't let invalid translators break all translation

If a translator couldn't be parsed, `_translatorInfo` wouldn't be set,
and that would somehow cause the translator info for subsequent
detections to be out of sync with the code loading, and nothing would
work. Putting a try/catch around the eval() allows subsequent
translators to continue to work normally. (There might be a better fix,
but this seems to work.)

This was happening for Better BibTeX translators that were still
installed without the extension (which they need to be parsed properly),
causing all imports to break.

https://forums.zotero.org/discussion/86613/error-id-1093166052-upload-of-ris-and-bibtex-data-failed
This commit is contained in:
Dan Stillman 2020-12-10 03:41:28 -05:00
parent 558ad20ce6
commit 31c928a3ff

View file

@ -1779,16 +1779,21 @@ Zotero.Translate.Base.prototype = {
var parse = function(code) {
Zotero.debug("Translate: Parsing code for " + translator.label + " "
+ "(" + translator.translatorID + ", " + translator.lastUpdated + ")", 4);
this._sandboxManager.eval(
"var exports = {}, ZOTERO_TRANSLATOR_INFO = " + code,
[
"detect" + this._entryFunctionSuffix,
"do" + this._entryFunctionSuffix,
"exports",
"ZOTERO_TRANSLATOR_INFO"
],
(translator.file ? translator.file.path : translator.label)
);
try {
this._sandboxManager.eval(
"var exports = {}, ZOTERO_TRANSLATOR_INFO = " + code,
[
"detect" + this._entryFunctionSuffix,
"do" + this._entryFunctionSuffix,
"exports",
"ZOTERO_TRANSLATOR_INFO"
],
(translator.file ? translator.file.path : translator.label)
);
}
catch (e) {
Zotero.logError(e);
}
this._translatorInfo = this._sandboxManager.sandbox.ZOTERO_TRANSLATOR_INFO;
}.bind(this);