Throw specific errors for missing objects or unknown fields
And add a bit more debugging info to other messages
This commit is contained in:
parent
258b70b455
commit
b4a8083f2f
2 changed files with 25 additions and 13 deletions
|
@ -265,7 +265,8 @@ Zotero.Item.prototype.getField = function(field, unformatted, includeBaseMapped)
|
||||||
// Zotero.Items.cacheFields()) or item data has to be loaded
|
// Zotero.Items.cacheFields()) or item data has to be loaded
|
||||||
if (this._identified && value === null && !this._loaded.itemData) {
|
if (this._identified && value === null && !this._loaded.itemData) {
|
||||||
throw new Zotero.Exception.UnloadedDataException(
|
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
|
// Convert any keys to ids
|
||||||
var collectionIDs = collectionIDsOrKeys.map(function (val) {
|
var collectionIDs = collectionIDsOrKeys.map(function (val) {
|
||||||
return parseInt(val) == val
|
if (parseInt(val) == val) {
|
||||||
? parseInt(val)
|
return parseInt(val);
|
||||||
: this.ContainerObjectsClass.getIDFromLibraryAndKey(this.libraryID, 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));
|
}.bind(this));
|
||||||
collectionIDs = Zotero.Utilities.arrayUnique(collectionIDs);
|
collectionIDs = Zotero.Utilities.arrayUnique(collectionIDs);
|
||||||
|
|
||||||
|
@ -3889,13 +3897,15 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
|
||||||
case 'accessDate':
|
case 'accessDate':
|
||||||
case 'dateAdded':
|
case 'dateAdded':
|
||||||
case 'dateModified':
|
case 'dateModified':
|
||||||
let d = Zotero.Date.isoToDate(val);
|
if (val) {
|
||||||
if (!d) {
|
let d = Zotero.Date.isoToDate(val);
|
||||||
Zotero.logError("Discarding invalid " + field + " '" + val
|
if (!d) {
|
||||||
+ "' for item " + this.libraryKey);
|
Zotero.logError("Discarding invalid " + field + " '" + val
|
||||||
continue;
|
+ "' for item " + this.libraryKey);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
val = Zotero.Date.dateToSQL(d, true);
|
||||||
}
|
}
|
||||||
val = Zotero.Date.dateToSQL(d, true);
|
|
||||||
if (field == 'accessDate') {
|
if (field == 'accessDate') {
|
||||||
this.setField(field, val);
|
this.setField(field, val);
|
||||||
}
|
}
|
||||||
|
@ -3945,7 +3955,7 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
|
||||||
|
|
||||||
case 'filename':
|
case 'filename':
|
||||||
if (val === "") {
|
if (val === "") {
|
||||||
Zotero.logError("Ignoring empty attachment filename in item JSON");
|
Zotero.logError("Ignoring empty attachment filename in JSON for item " + this.libraryKey);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.attachmentFilename = val;
|
this.attachmentFilename = val;
|
||||||
|
@ -3964,7 +3974,7 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
|
||||||
this.itemTypeID
|
this.itemTypeID
|
||||||
);
|
);
|
||||||
if (!isValidForType[field]) {
|
if (!isValidForType[field]) {
|
||||||
Zotero.logError("Discarding unknown JSON field " + field);
|
Zotero.logError("Discarding unknown JSON field " + field + " for item " + this.libraryKey);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.setField(field, json[field]);
|
this.setField(field, json[field]);
|
||||||
|
|
|
@ -2260,7 +2260,9 @@ Zotero.SearchConditions = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_conditions[condition]){
|
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'){
|
if (!operator && typeof _conditions[condition]['operators'] == 'undefined'){
|
||||||
|
|
Loading…
Reference in a new issue