- Fix error handling in syncing when using pumpGenerator()

- Take an optional error handler as the third parameter to pumpGenerator()
This commit is contained in:
Dan Stillman 2011-10-11 16:18:17 +00:00
parent ec6d38df68
commit 01ea59491a
2 changed files with 218 additions and 206 deletions

View File

@ -1460,10 +1460,27 @@ Zotero.Sync.Server = new function () {
);
}
var errorHandler = function (e) {
Zotero.DB.rollbackTransaction();
Zotero.UnresponsiveScriptIndicator.enable();
if (progressMeter) {
Zotero.hideZoteroPaneOverlay();
}
Zotero.suppressUIUpdates = false;
_updatesInProgress = false;
_error(e);
}
try {
var gen = Zotero.Sync.Server.Data.processUpdatedXML(
xml.updated, lastLocalSyncDate, syncSession, libraryID, function (xmlstr) {
try {
xml.updated,
lastLocalSyncDate,
syncSession,
libraryID,
function (xmlstr) {
Zotero.UnresponsiveScriptIndicator.enable();
if (progressMeter) {
@ -1654,26 +1671,12 @@ Zotero.Sync.Server = new function () {
Zotero.HTTP.doPost(url, body, uploadCallback);
}
}
catch (e) {
_error(e);
}
}
);
Zotero.pumpGenerator(gen);
Zotero.pumpGenerator(gen, false, errorHandler);
}
catch (e) {
Zotero.DB.rollbackTransaction();
Zotero.UnresponsiveScriptIndicator.enable();
if (progressMeter) {
Zotero.hideZoteroPaneOverlay();
}
Zotero.suppressUIUpdates = false;
_updatesInProgress = false;
throw (e);
errorHandler(e);
}
}
catch (e) {

View File

@ -1498,8 +1498,11 @@ const ZOTERO_CONFIG = {
/**
* Pumps a generator until it yields false. See itemTreeView.js for an example.
*
* If errorHandler is specified, exceptions in the generator will be caught
* and passed to the callback
*/
this.pumpGenerator = function(generator, ms) {
this.pumpGenerator = function(generator, ms, errorHandler) {
_waiting++;
var timer = Components.classes["@mozilla.org/timer;1"].
@ -1528,7 +1531,13 @@ const ZOTERO_CONFIG = {
_waitTimers = [];
_waitTimerCallbacks = [];
if(err) throw err;
if(err) {
if(errorHandler) {
errorHandler(err);
} else {
throw err;
}
}
}}
timer.initWithCallback(timerCallback, ms ? ms : 0, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
// add timer to global scope so that it doesn't get garbage collected before it completes