Bug 1289821 - Add logging to _winLookup if host manifest is missing r=zombie
authorgfmcknight <graham.mcknight2@gmail.com>
Tue, 09 Jul 2019 16:58:16 +0000
changeset 482044 3e5348e100e4b08c2dea2aa8439721609ae9aa31
parent 482043 9970aca55d089f9bddfd7a919b1d0734304a397d
child 482045 e4dd9975c68a50c3409512d92b2df40103bac9d1
push id113647
push useraciure@mozilla.com
push dateWed, 10 Jul 2019 09:46:39 +0000
treeherdermozilla-inbound@f3a387c13e2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszombie
bugs1289821
milestone70.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 1289821 - Add logging to _winLookup if host manifest is missing r=zombie Add logging to _winLookup if host manifest is missing Differential Revision: https://phabricator.services.mozilla.com/D36773
toolkit/components/extensions/NativeManifests.jsm
toolkit/components/extensions/test/xpcshell/test_native_manifests.js
--- a/toolkit/components/extensions/NativeManifests.jsm
+++ b/toolkit/components/extensions/NativeManifests.jsm
@@ -54,17 +54,17 @@ var NativeManifests = {
           `Native manifests are not supported on ${AppConstants.platform}`
         );
       }
       this._initializePromise = Schemas.load(NATIVE_MANIFEST_SCHEMA);
     }
     return this._initializePromise;
   },
 
-  _winLookup(type, name, context) {
+  async _winLookup(type, name, context) {
     const REGISTRY = Ci.nsIWindowsRegKey;
     let regPath = `${REGPATH}\\${TYPES[type]}\\${name}`;
     let path = WindowsRegistry.readRegKey(
       REGISTRY.ROOT_KEY_CURRENT_USER,
       regPath,
       "",
       REGISTRY.WOW64_64
     );
@@ -82,22 +82,22 @@ var NativeManifests = {
         regPath,
         "",
         REGISTRY.WOW64_64
       );
     }
     if (!path) {
       return null;
     }
-    return this._tryPath(type, path, name, context).then(manifest =>
-      manifest ? { path, manifest } : null
-    );
+
+    let manifest = await this._tryPath(type, path, name, context, true);
+    return manifest ? { path, manifest } : null;
   },
 
-  _tryPath(type, path, name, context) {
+  _tryPath(type, path, name, context, logIfNotFound) {
     return Promise.resolve()
       .then(() => OS.File.read(path, { encoding: "utf-8" }))
       .then(data => {
         let manifest;
         try {
           manifest = JSON.parse(data);
         } catch (ex) {
           Cu.reportError(
@@ -148,26 +148,31 @@ var NativeManifests = {
           );
           return;
         }
 
         return manifest;
       })
       .catch(ex => {
         if (ex instanceof OS.File.Error && ex.becauseNoSuchFile) {
+          if (logIfNotFound) {
+            Cu.reportError(
+              `Error reading native manifest file ${path}: file is referenced in the registry but does not exist`
+            );
+          }
           return null;
         }
         throw ex;
       });
   },
 
   async _tryPaths(type, name, dirs, context) {
     for (let dir of dirs) {
       let path = OS.Path.join(dir, TYPES[type], `${name}.json`);
-      let manifest = await this._tryPath(type, path, name, context);
+      let manifest = await this._tryPath(type, path, name, context, false);
       if (manifest) {
         return { path, manifest };
       }
     }
     return null;
   },
 
   /**
--- a/toolkit/components/extensions/test/xpcshell/test_native_manifests.js
+++ b/toolkit/components/extensions/test/xpcshell/test_native_manifests.js
@@ -152,16 +152,57 @@ add_task(async function test_nonexistent
     result,
     null,
     "lookupApplication returns null for non-existent application"
   );
 });
 
 const USER_TEST_JSON = OS.Path.join(userDir.path, TYPE_SLUG, "test.json");
 
+add_task(async function test_nonexistent_manifest_with_registry_entry() {
+  if (registry) {
+    registry.setValue(
+      Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+      `${REGPATH}\\test`,
+      "",
+      USER_TEST_JSON
+    );
+  }
+
+  await OS.File.remove(USER_TEST_JSON);
+  let { messages, result } = await promiseConsoleOutput(() =>
+    lookupApplication("test", context)
+  );
+  equal(
+    result,
+    null,
+    "lookupApplication returns null for non-existent manifest"
+  );
+
+  let noSuchFileErrors = messages.filter(logMessage =>
+    logMessage.message.includes(
+      "file is referenced in the registry but does not exist"
+    )
+  );
+
+  if (registry) {
+    equal(
+      noSuchFileErrors.length,
+      1,
+      "lookupApplication logs a non-existent manifest file pointed to by the registry"
+    );
+  } else {
+    equal(
+      noSuchFileErrors.length,
+      0,
+      "lookupApplication does not log about registry on non-windows platforms"
+    );
+  }
+});
+
 add_task(async function test_good_manifest() {
   await writeManifest(USER_TEST_JSON, templateManifest);
   if (registry) {
     registry.setValue(
       Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
       `${REGPATH}\\test`,
       "",
       USER_TEST_JSON