Fix possible restart error with invalid Quick Copy setting

If you had Quick Copy set to a missing translator, had a site-specific
Quick Copy setting, and loaded a page in the browser, the next click on
an item would result in a restart error.
This commit is contained in:
Dan Stillman 2018-08-12 19:02:05 -04:00
parent 6112002003
commit 5ad2a83b61
2 changed files with 12 additions and 2 deletions

View file

@ -161,7 +161,12 @@ const ZoteroStandalone = new function() {
if (format.mode == 'export') { if (format.mode == 'export') {
try { try {
let obj = Zotero.Translators.get(format.id); let obj = Zotero.Translators.get(format.id);
copyExport.label = Zotero.getString('quickCopy.copyAs', obj.label); if (obj) {
copyExport.label = Zotero.getString('quickCopy.copyAs', obj.label);
}
else {
copyExport.hidden = true;
}
} }
catch (e) { catch (e) {
if (!(e instanceof Zotero.Exception.UnloadedDataException && e.dataType == 'translators')) { if (!(e instanceof Zotero.Exception.UnloadedDataException && e.dataType == 'translators')) {

View file

@ -182,7 +182,8 @@ Zotero.QuickCopy = new function() {
} }
if (!_siteSettings) { if (!_siteSettings) {
throw new Zotero.Exception.UnloadedDataException("Quick Copy site settings not loaded"); Zotero.debug("Quick Copy site settings not loaded", 2);
return quickCopyPref;
} }
var matches = []; var matches = [];
@ -461,6 +462,10 @@ Zotero.QuickCopy = new function() {
Zotero.debug(`Preloading ${format.id} for Quick Copy`); Zotero.debug(`Preloading ${format.id} for Quick Copy`);
await Zotero.Translators.init(); await Zotero.Translators.init();
let translator = Zotero.Translators.get(format.id); let translator = Zotero.Translators.get(format.id);
if (!translator) {
Zotero.logError(`Translator ${format.id} not found`);
return;
}
translator.cacheCode = true; translator.cacheCode = true;
await translator.getCode(); await translator.getCode();
} }