Index: lib/src/runner/vm/catch_isolate_errors.dart |
diff --git a/lib/src/runner/vm/catch_isolate_errors.dart b/lib/src/runner/vm/catch_isolate_errors.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c42719726243b1437b1086e3bedbc88ab0672eb5 |
--- /dev/null |
+++ b/lib/src/runner/vm/catch_isolate_errors.dart |
@@ -0,0 +1,25 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import 'dart:isolate'; |
+import 'dart:async'; |
+ |
+import 'package:stack_trace/stack_trace.dart'; |
+ |
+/// Capture any top-level errors (mostly lazy syntax errors, since other are |
+/// caught below) and report them to the parent isolate. |
+void catchIsolateErrors() { |
+ var errorPort = new ReceivePort(); |
+ // Aet errors non-fatal because otherwise they'll be double-printed. |
+ Isolate.current.setErrorsFatal(false); |
+ Isolate.current.addErrorListener(errorPort.sendPort); |
+ errorPort.listen((message) { |
+ // Masquerade as an IsoalteSpawnException because that's what this would |
+ // be if the error had been detected statically. |
+ var error = new IsolateSpawnException(message[0]); |
+ var stackTrace = |
+ message[1] == null ? new Trace([]) : new Trace.parse(message[1]); |
+ Zone.current.handleUncaughtError(error, stackTrace); |
+ }); |
+} |