From 1cbc2440ec45ac085f2fad51443cada58a6cab98 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 19 May 2017 11:21:33 -0400 Subject: [PATCH] Make a missing related item not fatal Since item relations are synced with individual items, an item can exist before the item it's related to has been downloaded. --- chrome/content/zotero/bindings/relatedbox.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/bindings/relatedbox.xml b/chrome/content/zotero/bindings/relatedbox.xml index 3989dbbeaf..b421720719 100644 --- a/chrome/content/zotero/bindings/relatedbox.xml +++ b/chrome/content/zotero/bindings/relatedbox.xml @@ -81,6 +81,11 @@ if (keys.length) { for (let key of keys) { let item = Zotero.Items.getByLibraryAndKey(this.item.libraryID, key); + if (!item) { + Zotero.debug(`Related item ${this.item.libraryID}/${key} not found ` + + `for item ${this.item.libraryKey}`, 2); + continue; + } r = r + item.getDisplayTitle() + ", "; } r = r.substr(0,r.length-2); @@ -139,6 +144,11 @@ let relatedItem = Zotero.Items.getByLibraryAndKey( this.item.libraryID, key ); + if (!relatedItem) { + Zotero.debug(`Related item ${this.item.libraryID}/${key} not found ` + + `for item ${this.item.libraryKey}`, 2); + continue; + } let id = relatedItem.id; let icon = document.createElement("image"); icon.className = "zotero-box-icon"; @@ -194,7 +204,7 @@ } rows.appendChild(row); } - this.updateCount(relatedKeys.length); + this.updateCount(rows.childNodes.length); } ]]>