[canvaskit] Add catchException everywhere

This should make the logs in the bots more actionable by showing
the error and trace.

This also fixes the API change causing mysterious red.

Bug: skia:
Change-Id: I38df2bb4557041f8bdfefcae5c8d95b58e770033
Reviewed-on: https://skia-review.googlesource.com/c/168180
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/modules/pathkit/tests/testReporter.js b/modules/pathkit/tests/testReporter.js
index d1dcd7b..3879ec1 100644
--- a/modules/pathkit/tests/testReporter.js
+++ b/modules/pathkit/tests/testReporter.js
@@ -103,4 +103,23 @@
 
 function standardizedCanvasSize(ctx) {
     setCanvasSize(ctx, 600, 600);
+}
+
+// A wrapper to catch and print a stacktrace to the logs.
+// Exceptions normally shows up in the browser console,
+// but not in the logs that appear on the bots AND a thrown
+// exception will normally cause a test to time out.
+// This wrapper mitigates both those pain points.
+function catchException(done, fn) {
+    return () => {
+        try {
+            fn()
+        } catch (e) {
+            console.log('Failed with the following error', e);
+            done();
+        }
+        // We don't call done with finally because
+        // that would make the break the asynchronous nature
+        // of fn().
+    }
 }
\ No newline at end of file