ignore broken local snapshots if they can't be parsed; trigger an initial sync instead
authorDan Mills <thunder@mozilla.com>
Wed, 05 Mar 2008 17:11:08 -0800
changeset 44362 d77e6b94661780d0a8cc1352d37597b2943490f3
parent 44361 d95044856bb255e34ae739806f33d98b74d75bfb
child 44363 b03427f958ddbd5ccc1fb682d7afc18fe87cb7b3
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
ignore broken local snapshots if they can't be parsed; trigger an initial sync instead
services/sync/modules/stores.js
--- a/services/sync/modules/stores.js
+++ b/services/sync/modules/stores.js
@@ -205,26 +205,31 @@ SnapshotStore.prototype = {
     let file = this._dirSvc.get("ProfD", Ci.nsIFile);
     file.append("weave");
     file.append("snapshots");
     file.append(this.filename);
 
     if (!file.exists())
       return;
 
-    let [is] = Utils.open(file, "<");
-    let json = Utils.readStream(is);
-    is.close();
-    json = this._json.decode(json);
+    try {
+      let [is] = Utils.open(file, "<");
+      let json = Utils.readStream(is);
+      is.close();
+      json = this._json.decode(json);
 
-    if (json && 'snapshot' in json && 'version' in json && 'GUID' in json) {
-      this._log.info("Read saved snapshot from disk");
-      this.data = json.snapshot;
-      this.version = json.version;
-      this.GUID = json.GUID;
+      if (json && 'snapshot' in json && 'version' in json && 'GUID' in json) {
+        this._log.info("Read saved snapshot from disk");
+        this.data = json.snapshot;
+        this.version = json.version;
+        this.GUID = json.GUID;
+      }
+    } catch (e) {
+      this._log.warn("Could not parse saved snapshot; reverting to initial-sync state");
+      this._log.debug("Exception: " + e);
     }
   },
 
   serialize: function SStore_serialize() {
     let json = this._json.encode(this.data);
     json = json.replace(/:{type/g, ":\n\t{type");
     json = json.replace(/}, /g, "},\n  ");
     json = json.replace(/, parentGUID/g, ",\n\t parentGUID");