Bug 512457 - Report errors before they get eaten up by runInBatchMode

Save the exception from inside runBatched and not have runInBatchMode return failure, so we can then expose the exception.
This commit is contained in:
Edward Lee 2009-08-31 16:28:00 -07:00
parent 813888cd91
commit c70241b5ce
4 changed files with 44 additions and 10 deletions

View File

@ -93,11 +93,7 @@ BookmarksEngine.prototype = {
_storeObj: BookmarksStore,
_trackerObj: BookmarksTracker,
_sync: function BookmarksEngine__sync() {
Svc.Bookmark.runInBatchMode({
runBatched: Utils.bind2(this, SyncEngine.prototype._sync)
}, null);
}
_sync: Utils.batchSync("Bookmark", SyncEngine)
};
function BookmarksStore() {

View File

@ -81,11 +81,7 @@ HistoryEngine.prototype = {
_storeObj: HistoryStore,
_trackerObj: HistoryTracker,
_sync: function HistoryEngine__sync() {
Svc.History.runInBatchMode({
runBatched: Utils.bind2(this, SyncEngine.prototype._sync)
}, null);
},
_sync: Utils.batchSync("History", SyncEngine),
// History reconciliation is simpler than the default one from SyncEngine,
// because we have the advantage that we can use the URI as a definitive

View File

@ -124,6 +124,29 @@ let Utils = {
};
},
batchSync: function batchSync(service, engineType) {
return function batchedSync() {
let engine = this;
let batchEx = null;
// Try running sync in batch mode
Svc[service].runInBatchMode({
runBatched: function wrappedSync() {
try {
engineType.prototype._sync.call(engine);
}
catch(ex) {
batchEx = ex;
}
}
}, null);
// Expose the exception if something inside the batch failed
if (batchEx!= null)
throw batchEx;
};
},
// Generates a brand-new globally unique identifier (GUID).
makeGUID: function makeGUID() {
let uuidgen = Cc["@mozilla.org/uuid-generator;1"].

View File

@ -0,0 +1,19 @@
_("Making sure a failing sync reports a useful error");
Cu.import("resource://weave/engines/bookmarks.js");
function run_test() {
let engine = new BookmarksEngine();
engine._syncStartup = function() {
throw "FAIL!";
};
try {
_("Try calling the sync that should throw right away");
engine._sync();
do_throw("Should have failed sync!");
}
catch(ex) {
_("Making sure what we threw ended up as the exception:", ex);
do_check_eq(ex, "FAIL!");
}
}