commit 9441627e74ca0b8b705319d561a534720dd9a748
parent 31502de08f8c9cd5a6e3b5c81bdd5ec19391d6c8
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 10 Aug 2014 14:15:46 -0400
Allow StopIteration in queryAsync() to cancel query
And catch other errors and throw StopIteration so that they stop the
search. (Non-StopIteration errors in onRow don't stop Sqlite.jsm
queries. We were logging them but then re-throwing them, which didn't do
anything.)
Diffstat:
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js
@@ -656,15 +656,19 @@ Zotero.DBConnection.prototype.queryAsync = function (sql, params, options) {
}
}
if (options && options.onRow) {
- // Errors in onRow aren't shown by default, so we wrap them in a try/catch
+ // Errors in onRow don't stop the query unless StopIteration is thrown
onRow = function (row) {
try {
options.onRow(row);
}
catch (e) {
+ if (e instanceof StopIteration) {
+ Zotero.debug("Query cancelled");
+ throw e;
+ }
Zotero.debug(e, 1);
Components.utils.reportError(e);
- throw e;
+ throw StopIteration;
}
}
}