Bug 1389717 - Ensure `HistoryStore#changeItemID` waits for `fetchURLInfoForGuid`. r=tcsc draft
authorKit Cambridge <kit@yakshaving.ninja>
Fri, 11 Aug 2017 19:08:04 -0700
changeset 645954 4073401200b65901a18b2f610169861fa5c64dff
parent 645074 80ff3f300e05f38f96c385b03d1973a966a2bd35
child 726094 4b527f5d541d19831b75aab4117ff70e755752f0
push id73957
push userbmo:kit@mozilla.com
push dateMon, 14 Aug 2017 16:56:22 +0000
reviewerstcsc
bugs1389717
milestone57.0a1
Bug 1389717 - Ensure `HistoryStore#changeItemID` waits for `fetchURLInfoForGuid`. r=tcsc MozReview-Commit-ID: CAVdgurQxPj
services/sync/modules/engines/history.js
--- a/services/sync/modules/engines/history.js
+++ b/services/sync/modules/engines/history.js
@@ -153,17 +153,21 @@ HistoryStore.prototype = {
       return this.setGUID(uri);
     }
 
     // If the URI doesn't have a GUID and we didn't create one for it.
     return null;
   },
 
   async changeItemID(oldID, newID) {
-    this.setGUID(await PlacesSyncUtils.history.fetchURLInfoForGuid(oldID).url, newID);
+    let info = await PlacesSyncUtils.history.fetchURLInfoForGuid(oldID);
+    if (!info) {
+      throw new Error(`Can't change ID for nonexistent history entry ${oldID}`);
+    }
+    this.setGUID(info.url, newID);
   },
 
   async getAllIDs() {
     let urls = await PlacesSyncUtils.history.getAllURLs({ since: new Date((Date.now() - THIRTY_DAYS_IN_MS)), limit: MAX_HISTORY_UPLOAD });
 
     let urlsByGUID = {};
     for (let url of urls) {
       let guid = await this.GUIDForUri(url, true);