Bug 1453596 - [mochitest] Throw errors instead of strings to get line numbers. r=gbrown
authorHenrik Skupin <mail@hskupin.info>
Thu, 12 Apr 2018 12:10:26 +0200
changeset 413069 e67b96dc309cce5c44ad2d452e16bb9f72f83c65
parent 413068 14d208836dd3d26ad84c4ab1213314b0be778e88
child 413070 172094bca9a6e2f841e629aae292647e212d92c6
push id33833
push useraiakab@mozilla.com
push dateFri, 13 Apr 2018 09:41:15 +0000
treeherdermozilla-central@260e4c83c8a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1453596
milestone61.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 1453596 - [mochitest] Throw errors instead of strings to get line numbers. r=gbrown Without using "new Error()" there will always be line 0 referenced in the exception message. MozReview-Commit-ID: KGzVDShiLTW
testing/mochitest/server.js
--- a/testing/mochitest/server.js
+++ b/testing/mochitest/server.js
@@ -133,28 +133,28 @@ function runServer()
         var invalid = false;
         for (var i=0; i < 4; i++) {
           if (quads[i] < 0 || quads[i] > 255)
             invalid = true;
         }
         if (!invalid)
           gServerAddress = _SERVER_ADDR;
         else
-          throw "invalid _SERVER_ADDR, please specify a valid IP Address";
+          throw new Error("invalid _SERVER_ADDR, please specify a valid IP Address");
       }
     }
   } else {
-    throw "please defined _SERVER_ADDR (as an ip address) before running server.js";
+    throw new Error("please define _SERVER_ADDR (as an ip address) before running server.js");
   }
 
   if (typeof(_SERVER_PORT) != "undefined") {
     if (parseInt(_SERVER_PORT) > 0 && parseInt(_SERVER_PORT) < 65536)
       SERVER_PORT = _SERVER_PORT;
   } else {
-    throw "please define _SERVER_PORT (as a port number) before running server.js";
+    throw new Error("please define _SERVER_PORT (as a port number) before running server.js");
   }
 
   // If DISPLAY_RESULTS is not specified, it defaults to true
   if (typeof(_DISPLAY_RESULTS) != "undefined") {
     displayResults = _DISPLAY_RESULTS;
   }
 
   server._start(SERVER_PORT, gServerAddress);
@@ -289,27 +289,27 @@ function processLocations(server)
     lineno++;
 
     var lineValue = line.value;
     if (lineValue.charAt(0) == "#" || lineValue == "")
       continue;
 
     var match = LINE_REGEXP.exec(lineValue);
     if (!match)
-      throw "Syntax error in server-locations.txt, line " + lineno;
+      throw new Error("Syntax error in server-locations.txt, line " + lineno);
 
     var [, scheme, host, port, options] = match;
     if (options)
     {
       if (options.split(",").includes("primary"))
       {
         if (seenPrimary)
         {
-          throw "Multiple primary locations in server-locations.txt, " +
-                "line " + lineno;
+          throw new Error("Multiple primary locations in server-locations.txt, " +
+                          "line " + lineno);
         }
 
         server.identity.setPrimary(scheme, host, port);
         seenPrimary = true;
         continue;
       }
     }