Bug 1212297 - improve error handling in Chrome bookmarks migration code, r=MattN
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 07 Oct 2015 13:24:50 +0100
changeset 266936 eb5a0b994ea9b98962b91b5116b07d7ce5c2dcf0
parent 266935 65738b3a3f9df0d07970687e5646a6a62f3327db
child 266937 ba28fd929617d3673936f8a31ef40e3e6017f3c8
push id29503
push usercbook@mozilla.com
push dateFri, 09 Oct 2015 09:36:47 +0000
treeherdermozilla-central@462074ffada4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1212297
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1212297 - improve error handling in Chrome bookmarks migration code, r=MattN
browser/components/migration/ChromeProfileMigrator.js
--- a/browser/components/migration/ChromeProfileMigrator.js
+++ b/browser/components/migration/ChromeProfileMigrator.js
@@ -47,33 +47,41 @@ function chromeTimeToDate(aTime)
 
 /**
  * Insert bookmark items into specific folder.
  *
  * @param   parentGuid
  *          GUID of the folder where items will be inserted
  * @param   items
  *          bookmark items to be inserted
+ * @param   errorAccumulator
+ *          function that gets called with any errors thrown so we don't drop them on the floor.
  */
-function* insertBookmarkItems(parentGuid, items) {
+function* insertBookmarkItems(parentGuid, items, errorAccumulator) {
   for (let item of items) {
     try {
       if (item.type == "url") {
+        if (item.url.trim().startsWith("chrome:")) {
+          // Skip invalid chrome URIs. Creating an actual URI always reports
+          // messages to the console, so we avoid doing that.
+          continue;
+        }
         yield PlacesUtils.bookmarks.insert({
           parentGuid, url: item.url, title: item.name
         });
       } else if (item.type == "folder") {
         let newFolderGuid = (yield PlacesUtils.bookmarks.insert({
           parentGuid, type: PlacesUtils.bookmarks.TYPE_FOLDER, title: item.name
         })).guid;
 
-        yield insertBookmarkItems(newFolderGuid, item.children);
+        yield insertBookmarkItems(newFolderGuid, item.children, errorAccumulator);
       }
     } catch (e) {
       Cu.reportError(e);
+      errorAccumulator(e);
     }
   }
 }
 
 
 function ChromeProfileMigrator() {
   let chromeUserDataFolder = FileUtils.getDir(
 #ifdef XP_WIN
@@ -197,16 +205,18 @@ function GetBookmarksResource(aProfileFo
   if (!bookmarksFile.exists())
     return null;
 
   return {
     type: MigrationUtils.resourceTypes.BOOKMARKS,
 
     migrate: function(aCallback) {
       return Task.spawn(function* () {
+        let gotErrors = false;
+        let errorGatherer = () => gotErrors = true;
         let jsonStream = yield new Promise(resolve =>
           NetUtil.asyncFetch({ uri: NetUtil.newURI(bookmarksFile),
                                loadUsingSystemPrincipal: true
                              },
                              (inputStream, resultCode) => {
                                if (Components.isSuccessCode(resultCode)) {
                                  resolve(inputStream);
                                } else {
@@ -225,32 +235,35 @@ function GetBookmarksResource(aProfileFo
         if (roots.bookmark_bar.children &&
             roots.bookmark_bar.children.length > 0) {
           // Toolbar
           let parentGuid = PlacesUtils.bookmarks.toolbarGuid;
           if (!MigrationUtils.isStartupMigration) {
             parentGuid =
               yield MigrationUtils.createImportedBookmarksFolder("Chrome", parentGuid);
           }
-          yield insertBookmarkItems(parentGuid, roots.bookmark_bar.children);
+          yield insertBookmarkItems(parentGuid, roots.bookmark_bar.children, errorGatherer);
         }
 
         // Importing bookmark menu items
         if (roots.other.children &&
             roots.other.children.length > 0) {
           // Bookmark menu
           let parentGuid = PlacesUtils.bookmarks.menuGuid;
           if (!MigrationUtils.isStartupMigration) {
             parentGuid =
               yield MigrationUtils.createImportedBookmarksFolder("Chrome", parentGuid);
           }
-          yield insertBookmarkItems(parentGuid, roots.other.children);
+          yield insertBookmarkItems(parentGuid, roots.other.children, errorGatherer);
+        }
+        if (gotErrors) {
+          throw "The migration included errors.";
         }
       }.bind(this)).then(() => aCallback(true),
-                          e => { Cu.reportError(e); aCallback(false) });
+                          e => aCallback(false));
     }
   };
 }
 
 function GetHistoryResource(aProfileFolder) {
   let historyFile = aProfileFolder.clone();
   historyFile.append("History");
   if (!historyFile.exists())