commit e716a5367a357b6ac20fd0695f47e273ccf7bc59
parent d08ad1143dad4ea614742c7dc5f2927d213d20e3
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 11 Apr 2013 04:25:22 -0400
Some file sync errors weren't being caught and displayed
Diffstat:
4 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/storage/queue.js b/chrome/content/zotero/xpcom/storage/queue.js
@@ -413,7 +413,7 @@ Zotero.Sync.Storage.Queue.prototype.stop = function () {
this._stopping = true;
for each(var request in this._requests) {
if (!request.isFinished()) {
- request.stop();
+ request.stop(true);
}
}
diff --git a/chrome/content/zotero/xpcom/storage/request.js b/chrome/content/zotero/xpcom/storage/request.js
@@ -48,6 +48,7 @@ Zotero.Sync.Storage.Request = function (name, callbacks) {
this._remaining = null;
this._maxSize = null;
this._finished = false;
+ this._forceFinish = false;
this._changesMade = false;
for (var func in callbacks) {
@@ -308,7 +309,11 @@ Zotero.Sync.Storage.Request.prototype.onProgress = function (channel, progress,
/**
* Stop the request's underlying network request, if there is one
*/
-Zotero.Sync.Storage.Request.prototype.stop = function () {
+Zotero.Sync.Storage.Request.prototype.stop = function (force) {
+ if (force) {
+ this._forceFinish = true;
+ }
+
if (this.channel) {
this._stopping = true;
@@ -330,6 +335,15 @@ Zotero.Sync.Storage.Request.prototype.stop = function () {
* Mark request as finished and notify queue that it's done
*/
Zotero.Sync.Storage.Request.prototype._finish = function () {
+ // If an error occurred, we wait to finish the request, since doing
+ // so might end the queue before the error flag has been set on the queue.
+ // When the queue's error handler stops the queue, it stops the request
+ // with stop(true) to force the finish to occur, allowing the queue's
+ // promise to be rejected with the error.
+ if (!this._forceFinish && this._deferred.promise.isRejected()) {
+ return;
+ }
+
Zotero.debug("Finishing " + this.queue.name + " request '" + this.name + "'");
this._finished = true;
var active = this._running;
diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js
@@ -271,6 +271,8 @@ Zotero.Sync.Storage.WebDAV = (function () {
request.onProgress(a, b, c);
},
onStop: function (httpRequest, status, response, data) {
+ data.request.setChannel(false);
+
deferred.resolve(
Q.fcall(function () {
return onUploadComplete(httpRequest, status, response, data);
@@ -880,6 +882,8 @@ Zotero.Sync.Storage.WebDAV = (function () {
request.onProgress(a, b, c)
},
onStop: function (request, status, response, data) {
+ data.request.setChannel(false);
+
if (status == 404) {
var msg = "Remote ZIP file not found for item " + item.key;
Zotero.debug(msg, 2);
diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js
@@ -463,6 +463,8 @@ Zotero.Sync.Storage.ZFS = (function () {
request.onProgress(a, b, c);
},
onStop: function (httpRequest, status, response, data) {
+ data.request.setChannel(false);
+
deferred.resolve(
onUploadComplete(httpRequest, status, response, data)
);
@@ -803,6 +805,8 @@ Zotero.Sync.Storage.ZFS = (function () {
request.onProgress(a, b, c)
},
onStop: function (request, status, response, data) {
+ data.request.setChannel(false);
+
if (status != 200) {
var msg = "Unexpected status code " + status
+ " for request " + data.request.name