www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit ab4138cf26123749fb2b31880c0ee39313e882e3
parent bf3ad6a2a41fd3f9783157f0cfadde5f537a8a55
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu,  5 May 2016 06:03:32 -0400

Don't throw in Zotero.DataObjects::get() for nonexistent objects

Return false for single ids or skip for multiple ids. This is the original
behavior, but at some point it started throwing an UnloadedDataException. IDs
are always loaded at initialization, though, so we know whether the objects
actually exist.

Diffstat:
Mchrome/content/zotero/xpcom/data/dataObjects.js | 11++++++++++-
Mtest/tests/dataObjectsTest.js | 6++++++
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js @@ -118,7 +118,16 @@ Zotero.DataObjects.prototype.get = function (ids) { let id = ids[i]; // Check if already loaded if (!this._objectCache[id]) { - throw new Zotero.Exception.UnloadedDataException(this._ZDO_Object + " " + id + " not yet loaded"); + // If unloaded id is registered, throw an error + if (this._objectKeys[id]) { + throw new Zotero.Exception.UnloadedDataException( + this._ZDO_Object + " " + id + " not yet loaded" + ); + } + // Otherwise ignore (which means returning false for a single id) + else { + continue; + } } toReturn.push(this._objectCache[id]); } diff --git a/test/tests/dataObjectsTest.js b/test/tests/dataObjectsTest.js @@ -3,6 +3,12 @@ describe("Zotero.DataObjects", function () { var types = ['collection', 'item', 'search']; + describe("#get()", function () { + it("should return false for nonexistent objects", function* () { + assert.isFalse(Zotero.Items.get(3464363)); + }); + }); + describe("#getLibraryAndKeyFromID()", function () { it("should return a libraryID and key within a transaction", function* () { for (let type of types) {