Bug 1493709 - Do not report error of dump load in RemoteSettings.get() r=glasserc
authorMathieu Leplatre <mathieu@mozilla.com>
Thu, 11 Oct 2018 13:53:54 +0000
changeset 499202 4afbb7a68839e5ca3635b708eece2c5a9e205475
parent 499201 c2666a1b9efc528357fd2481728f928560e0d3bd
child 499203 7bd7b375eb2ec849a949ba93abd30b3ea6f97919
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglasserc
bugs1493709
milestone64.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 1493709 - Do not report error of dump load in RemoteSettings.get() r=glasserc If the collection has no local dump, it should not report any error while trying to load the dump. Differential Revision: https://phabricator.services.mozilla.com/D7889
services/settings/remote-settings.js
--- a/services/settings/remote-settings.js
+++ b/services/settings/remote-settings.js
@@ -220,27 +220,39 @@ async function fetchLatestChanges(url, l
     }
   }
 
   return {changes, currentEtag, serverTimeMillis, backoffSeconds};
 }
 
 /**
  * Load the the JSON file distributed with the release for this collection.
- * @param {String} bucket
- * @param {String} collection
+ * @param {String}  bucket
+ * @param {String}  collection
+ * @param {Object}  options
+ * @param {boolean} options.ignoreMissing Do not throw an error if the file is missing.
  */
-async function loadDumpFile(bucket, collection) {
+async function loadDumpFile(bucket, collection, { ignoreMissing = true } = {}) {
   const fileURI = `resource://app/defaults/settings/${bucket}/${collection}.json`;
-  const response = await fetch(fileURI);
-  if (!response.ok) {
-    throw new Error(`Could not read from '${fileURI}'`);
+  let response;
+  try {
+    // Will throw NetworkError is folder/file is missing.
+    response = await fetch(fileURI);
+    if (!response.ok) {
+      throw new Error(`Could not read from '${fileURI}'`);
+    }
+    // Will throw if JSON is invalid.
+    return response.json();
+  } catch (e) {
+    // A missing file is reported as "NetworError" (see Bug 1493709)
+    if (!ignoreMissing || !/NetworkError/.test(e.message)) {
+      throw e;
+    }
   }
-  // Will be rejected if JSON is invalid.
-  return response.json();
+  return { data: [] };
 }
 
 
 class RemoteSettingsClient {
 
   constructor(collectionName, { bucketNamePref, signerName, filterFunc = jexlFilterFunc, localFields = [], lastCheckTimePref }) {
     this.collectionName = collectionName;
     this.signerName = signerName;
@@ -611,17 +623,17 @@ async function hasLocalData(client) {
  * Check if we ship a JSON dump for the specified bucket and collection.
  *
  * @param {String} bucket
  * @param {String} collection
  * @return {bool} Whether it is present or not.
  */
 async function hasLocalDump(bucket, collection) {
   try {
-    await loadDumpFile(bucket, collection);
+    await loadDumpFile(bucket, collection, {ignoreMissing: false});
     return true;
   } catch (e) {
     return false;
   }
 }
 
 
 function remoteSettingsFunction() {