Fix "params.join is not a function" in DB.queryAsync() error logging

If a query failed and `params` wasn't an array, the "params.join is not
a function" would be thrown rather than a proper error.
This commit is contained in:
Dan Stillman 2020-05-12 03:43:24 -04:00
parent 0199428c57
commit 6d2e843f50

View file

@ -662,7 +662,13 @@ Zotero.DBConnection.prototype.queryAsync = Zotero.Promise.coroutine(function* (s
var eStr = e + "";
eStr = eStr.indexOf("Error: ") == 0 ? eStr.substr(7): e;
throw new Error(eStr + ' [QUERY: ' + sql + '] '
+ (params ? '[PARAMS: ' + params.join(', ') + '] ' : '')
+ (params
? '[PARAMS: '
+ (Array.isArray(params)
? params.map(x => JSON.stringify(x)).join(', ')
: JSON.stringify(params)
) + '] '
: '')
+ '[ERROR: ' + e.errors[0].message + ']');
}
else {