From 9441627e74ca0b8b705319d561a534720dd9a748 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 10 Aug 2014 14:15:46 -0400 Subject: [PATCH] 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.) --- chrome/content/zotero/xpcom/db.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index 63cff3c53..43565990a 100644 --- 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; } } }