Bug 1420577 - Improve failure messages for invalid proxy configurations. r=ato, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Mon, 04 Dec 2017 23:32:44 +0100
changeset 445231 e76ff14f1538e77ee2a7569e1eab3a16924feab4
parent 445230 965c4569f8c42113776c626f23e0a034b391d074
child 445232 019a43b61a5b2f48824f8e795a4c39659b1ef43b
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1420577
milestone58.0
Bug 1420577 - Improve failure messages for invalid proxy configurations. r=ato, a=test-only MozReview-Commit-ID: 4HitwxCUQH
testing/marionette/session.js
--- a/testing/marionette/session.js
+++ b/testing/marionette/session.js
@@ -7,17 +7,22 @@
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.importGlobalProperties(["URL"]);
 
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 Cu.import("chrome://marionette/content/assert.js");
-const {InvalidArgumentError} = Cu.import("chrome://marionette/content/error.js", {});
+const {
+  InvalidArgumentError,
+} = Cu.import("chrome://marionette/content/error.js", {});
+const {
+  pprint,
+} = Cu.import("chrome://marionette/content/format.js", {});
 
 this.EXPORTED_SYMBOLS = ["session"];
 
 // Enable testing this module, as Services.appinfo.* is not available
 // in xpcshell tests.
 const appinfo = {name: "<missing>", version: "<missing>"};
 try { appinfo.name = Services.appinfo.name.toLowerCase(); } catch (e) {}
 try { appinfo.version = Services.appinfo.version; } catch (e) {}
@@ -197,17 +202,18 @@ session.Proxy = class {
    */
   static fromJSON(json) {
     function stripBracketsFromIpv6Hostname(hostname) {
       return hostname.includes(":") ? hostname.replace(/[\[\]]/g, "") : hostname;
     }
 
     // Parse hostname and optional port from host
     function fromHost(scheme, host) {
-      assert.string(host);
+      assert.string(host,
+          pprint`Expected proxy "host" to be a string, got ${host}`);
 
       if (host.includes("://")) {
         throw new InvalidArgumentError(`${host} contains a scheme`);
       }
 
       let url;
       try {
         // To parse the host a scheme has to be added temporarily.
@@ -248,29 +254,33 @@ session.Proxy = class {
       return [hostname, port];
     }
 
     let p = new session.Proxy();
     if (typeof json == "undefined" || json === null) {
       return p;
     }
 
-    assert.object(json);
+    assert.object(json, pprint`Expected "proxy" to be an object, got ${json}`);
 
-    assert.in("proxyType", json);
-    p.proxyType = assert.string(json.proxyType);
+    assert.in("proxyType", json,
+        pprint`Expected "proxyType" in "proxy" object, got ${json}`);
+    p.proxyType = assert.string(json.proxyType,
+        pprint`Expected "proxyType" to be a string, got ${json.proxyType}`);
 
     switch (p.proxyType) {
       case "autodetect":
       case "direct":
       case "system":
         break;
 
       case "pac":
-        p.proxyAutoconfigUrl = assert.string(json.proxyAutoconfigUrl);
+        p.proxyAutoconfigUrl = assert.string(json.proxyAutoconfigUrl,
+            `Expected "proxyAutoconfigUrl" to be a string, ` +
+            pprint`got ${json.proxyAutoconfigUrl}`);
         break;
 
       case "manual":
         if (typeof json.ftpProxy != "undefined") {
           [p.ftpProxy, p.ftpProxyPort] = fromHost("ftp", json.ftpProxy);
         }
         if (typeof json.httpProxy != "undefined") {
           [p.httpProxy, p.httpProxyPort] = fromHost("http", json.httpProxy);
@@ -278,19 +288,21 @@ session.Proxy = class {
         if (typeof json.sslProxy != "undefined") {
           [p.sslProxy, p.sslProxyPort] = fromHost("https", json.sslProxy);
         }
         if (typeof json.socksProxy != "undefined") {
           [p.socksProxy, p.socksProxyPort] = fromHost("socks", json.socksProxy);
           p.socksVersion = assert.positiveInteger(json.socksVersion);
         }
         if (typeof json.noProxy != "undefined") {
-          let entries = assert.array(json.noProxy);
+          let entries = assert.array(json.noProxy,
+              pprint`Expected "noProxy" to be an array, got ${json.noProxy}`);
           p.noProxy = entries.map(entry => {
-            assert.string(entry);
+            assert.string(entry,
+                pprint`Expected "noProxy" entry to be a string, got ${entry}`);
             return stripBracketsFromIpv6Hostname(entry);
           });
         }
         break;
 
       default:
         throw new InvalidArgumentError(
             `Invalid type of proxy: ${p.proxyType}`);