Title: [163196] trunk/Tools
Revision
163196
Author
[email protected]
Date
2014-01-31 13:56:30 -0800 (Fri, 31 Jan 2014)

Log Message

WebKit Bot Watcher's Dashboard: Teach JSON.load() to take optional failure callback function
https://bugs.webkit.org/show_bug.cgi?id=127924

Reviewed by Alexey Proskuryakov.

Towards providing better error handling when a JSON load fails with a non-200 HTTP status
code, we should teach JSON.load() to take an optional failure callback function and invoke
it when either a load error or a JSON parsing error occurs.

As a side benefit of having a failure callback function a caller can separate the error handling
logic for a JSON load or parse error from the logic of handling a successful parsing of JSON content.

* BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotIteration.js:
(BuildbotIteration.prototype.loadLayoutTestResults): Move JSON parser error logic into failure
callback function.
* BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Utilities.js:
(JSON.load): Modified to take optional failure callback function called failureCallback.

Modified Paths

Diff

Modified: trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotIteration.js (163195 => 163196)


--- trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotIteration.js	2014-01-31 21:34:38 UTC (rev 163195)
+++ trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotIteration.js	2014-01-31 21:56:30 UTC (rev 163196)
@@ -339,12 +339,6 @@
         }
 
         JSON.load(this.queue.buildbot.layoutTestFullResultsURLForIteration(this), function(data) {
-            if (data.error) {
-                console.log(data.error);
-                callback();
-                return;
-            }
-
             this.hasPrettyPatch = data.has_pretty_patch;
 
             this.layoutTestResults.regressions = collectResults(data.tests, function(info) { return info["report"] === "REGRESSION" });
@@ -357,6 +351,10 @@
             console.assert(data.num_missing === this.layoutTestResults.testsWithMissingResults.length);
 
             callback();
-        }.bind(this), {jsonpCallbackName: "ADD_RESULTS"});
+        }.bind(this),
+        function(data) {
+            console.log(data.error);
+            callback();
+        }, {jsonpCallbackName: "ADD_RESULTS"});
     }
 };

Modified: trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Utilities.js (163195 => 163196)


--- trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Utilities.js	2014-01-31 21:34:38 UTC (rev 163195)
+++ trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Utilities.js	2014-01-31 21:56:30 UTC (rev 163196)
@@ -23,13 +23,19 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-JSON.load = function(url, callback, options)
+JSON.LoadError = "JSONLoadError";
+JSON.ParseError = "JSONParseError";
+
+JSON.load = function(url, successCallback, failureCallback, options)
 {
     console.assert(url);
 
-    if (!(callback instanceof Function))
+    if (!(successCallback instanceof Function))
         return;
 
+    if (!(failureCallback instanceof Function))
+        failureCallback = function() { };
+
     if (typeof options !== "object")
         options = {};
 
@@ -38,18 +44,25 @@
         if (this.readyState !== 4)
             return;
 
+        // Don't consider a status of 0 to be a load error for easier testing with local files.
+        var loadErrorOccurred = this.status !== 0 && this.status !== 200;
+        if (loadErrorOccurred) {
+            failureCallback({errorType: JSON.LoadError, error: this.statusText, errorHTTPCode: this.status});
+            return;
+        }
+
         try {
             var responseText = request.responseText;
             if (options.hasOwnProperty("jsonpCallbackName"))
                 responseText = responseText.replace(new RegExp("^" + options.jsonpCallbackName + "\\((.*)\\);?$"), "$1");
             var data = ""
         } catch (e) {
-            var data = "" e.message};
+            var data = "" JSON.ParseError, error: e.message};
+            failureCallback(data);
+            return;
         }
 
-        // Allow a status of 0 for easier testing with local files.
-        if (!this.status || this.status === 200)
-            callback(data);
+        successCallback(data);
     };
 
     request.open("GET", url);

Modified: trunk/Tools/ChangeLog (163195 => 163196)


--- trunk/Tools/ChangeLog	2014-01-31 21:34:38 UTC (rev 163195)
+++ trunk/Tools/ChangeLog	2014-01-31 21:56:30 UTC (rev 163196)
@@ -1,3 +1,23 @@
+2014-01-31  Daniel Bates  <[email protected]>
+
+        WebKit Bot Watcher's Dashboard: Teach JSON.load() to take optional failure callback function
+        https://bugs.webkit.org/show_bug.cgi?id=127924
+
+        Reviewed by Alexey Proskuryakov.
+
+        Towards providing better error handling when a JSON load fails with a non-200 HTTP status
+        code, we should teach JSON.load() to take an optional failure callback function and invoke
+        it when either a load error or a JSON parsing error occurs.
+
+        As a side benefit of having a failure callback function a caller can separate the error handling
+        logic for a JSON load or parse error from the logic of handling a successful parsing of JSON content.
+
+        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/BuildbotIteration.js:
+        (BuildbotIteration.prototype.loadLayoutTestResults): Move JSON parser error logic into failure
+        callback function.
+        * BuildSlaveSupport/build.webkit.org-config/public_html/dashboard/Scripts/Utilities.js:
+        (JSON.load): Modified to take optional failure callback function called failureCallback.
+
 2014-01-29  Oliver Hunt  <[email protected]>
 
         Make it possible to implement JS builtins in JS
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to