commit b4a8083f2f5ba8b57e805f57a091b53c2e6dea3d
parent 258b70b455c3c23743ef1f1014a7d401a1792d57
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 20 Jul 2015 17:18:34 -0400
Throw specific errors for missing objects or unknown fields
And add a bit more debugging info to other messages
Diffstat:
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -265,7 +265,8 @@ Zotero.Item.prototype.getField = function(field, unformatted, includeBaseMapped)
// Zotero.Items.cacheFields()) or item data has to be loaded
if (this._identified && value === null && !this._loaded.itemData) {
throw new Zotero.Exception.UnloadedDataException(
- "Item data not loaded and field '" + field + "' not set", "itemData"
+ "Item data not loaded and field '" + field + "' not set for item " + this.libraryKey,
+ "itemData"
);
}
@@ -3350,9 +3351,16 @@ Zotero.Item.prototype.setCollections = function (collectionIDsOrKeys) {
// Convert any keys to ids
var collectionIDs = collectionIDsOrKeys.map(function (val) {
- return parseInt(val) == val
- ? parseInt(val)
- : this.ContainerObjectsClass.getIDFromLibraryAndKey(this.libraryID, val);
+ if (parseInt(val) == val) {
+ return parseInt(val);
+ }
+ var id = this.ContainerObjectsClass.getIDFromLibraryAndKey(this.libraryID, val);
+ if (!id) {
+ let e = new Error("Collection " + val + " not found for item " + this.libraryKey);
+ e.name = "ZoteroObjectNotFoundError";
+ throw e;
+ }
+ return id;
}.bind(this));
collectionIDs = Zotero.Utilities.arrayUnique(collectionIDs);
@@ -3889,13 +3897,15 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
case 'accessDate':
case 'dateAdded':
case 'dateModified':
- let d = Zotero.Date.isoToDate(val);
- if (!d) {
- Zotero.logError("Discarding invalid " + field + " '" + val
- + "' for item " + this.libraryKey);
- continue;
+ if (val) {
+ let d = Zotero.Date.isoToDate(val);
+ if (!d) {
+ Zotero.logError("Discarding invalid " + field + " '" + val
+ + "' for item " + this.libraryKey);
+ continue;
+ }
+ val = Zotero.Date.dateToSQL(d, true);
}
- val = Zotero.Date.dateToSQL(d, true);
if (field == 'accessDate') {
this.setField(field, val);
}
@@ -3945,7 +3955,7 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
case 'filename':
if (val === "") {
- Zotero.logError("Ignoring empty attachment filename in item JSON");
+ Zotero.logError("Ignoring empty attachment filename in JSON for item " + this.libraryKey);
}
else {
this.attachmentFilename = val;
@@ -3964,7 +3974,7 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
this.itemTypeID
);
if (!isValidForType[field]) {
- Zotero.logError("Discarding unknown JSON field " + field);
+ Zotero.logError("Discarding unknown JSON field " + field + " for item " + this.libraryKey);
continue;
}
this.setField(field, json[field]);
diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js
@@ -2260,7 +2260,9 @@ Zotero.SearchConditions = new function(){
}
if (!_conditions[condition]){
- throw new Error("Invalid condition '" + condition + "' in hasOperator()");
+ var e = new Error("Invalid condition '" + condition + "' in hasOperator()");
+ e.name = "ZoteroUnknownFieldError";
+ throw e;
}
if (!operator && typeof _conditions[condition]['operators'] == 'undefined'){