Bug 1525762: Part 1d - Don't throw from hasResource for resources that don't exist. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Fri, 22 Mar 2019 09:35:22 -0700
changeset 466964 f595c6ccb68af17285f3aefe96e9124a2b3cc81f
parent 466963 935a2cd834c2a489a585dec44cbc90964471501c
child 466965 cc45935ed2c2f3ae4627584f5c7318cb52271875
push id35789
push userbtara@mozilla.com
push dateSun, 31 Mar 2019 09:00:52 +0000
treeherdermozilla-central@c06dfc552c64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1525762
milestone68.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 1525762: Part 1d - Don't throw from hasResource for resources that don't exist. r=aswan When attempting to fetch a local resource which doesn't exist, the fetch promise rejects, causing the hasResource promise to reject. Since we don't want hasResource to reject for nonexistent resources, we need to catch this rejection and treat it as a nonexistent resource.
toolkit/mozapps/extensions/internal/XPIInstall.jsm
--- a/toolkit/mozapps/extensions/internal/XPIInstall.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIInstall.jsm
@@ -3663,18 +3663,22 @@ var XPIInstall = {
       file: null,
       verifySignedState() {
         return {
           signedState: AddonManager.SIGNEDSTATE_NOT_REQUIRED,
           cert: null,
         };
       },
       async hasResource(path) {
-        let response = await fetch(this.rootURI.resolve(path));
-        return response.ok;
+        try {
+          let response = await fetch(this.rootURI.resolve(path));
+          return response.ok;
+        } catch (e) {
+          return false;
+        }
       },
     };
 
     let addon = await loadManifest(pkg, XPIInternal.BuiltInLocation);
     addon.rootURI = base;
     await this._activateAddon(addon);
   },