Index: runtime/lib/isolate_patch.dart |
diff --git a/runtime/lib/isolate_patch.dart b/runtime/lib/isolate_patch.dart |
index 39826f656a469ed179aab3353180142ac6db3dd9..ff4f0c67c38babe4d650f8904ad8d153a278125f 100644 |
--- a/runtime/lib/isolate_patch.dart |
+++ b/runtime/lib/isolate_patch.dart |
@@ -253,18 +253,7 @@ patch class Isolate { |
// The VM will invoke [_startIsolate] with entryPoint as argument. |
readyPort = new RawReceivePort(); |
_spawnFunction(readyPort.sendPort, entryPoint, message); |
- Completer completer = new Completer<Isolate>.sync(); |
- readyPort.handler = (readyMessage) { |
- readyPort.close(); |
- assert(readyMessage is List); |
- assert(readyMessage.length == 2); |
- SendPort controlPort = readyMessage[0]; |
- List capabilities = readyMessage[1]; |
- completer.complete(new Isolate(controlPort, |
- pauseCapability: capabilities[0], |
- terminateCapability: capabilities[1])); |
- }; |
- return completer.future; |
+ return spawnCommon(readyPort); |
} catch (e, st) { |
if (readyPort != null) { |
readyPort.close(); |
@@ -281,23 +270,34 @@ patch class Isolate { |
// The VM will invoke [_startIsolate] and not `main`. |
readyPort = new RawReceivePort(); |
_spawnUri(readyPort.sendPort, uri.toString(), args, message); |
- Completer completer = new Completer<Isolate>.sync(); |
- readyPort.handler = (readyMessage) { |
+ return spawnCommon(readyPort); |
+ } catch (e, st) { |
+ if (readyPort != null) { |
readyPort.close(); |
- assert(readyMessage is List); |
- assert(readyMessage.length == 2); |
+ } |
+ return new Future<Isolate>.error(e, st); |
+ }; |
+ } |
+ |
+ static Future<Isolate> spawnCommon(RawReceivePort readyPort) { |
+ Completer completer = new Completer<Isolate>.sync(); |
+ readyPort.handler = (readyMessage) { |
+ readyPort.close(); |
+ if (readyMessage is String) { |
+ // We encountered an error starting the new isolate. |
+ completer.completeError(new IsolateSpawnException( |
+ "Unable to spawn child isolate:\n${readyMessage}")); |
+ } else if (readyMessage is List && |
+ readyMessage.length == 2) { |
SendPort controlPort = readyMessage[0]; |
List capabilities = readyMessage[1]; |
completer.complete(new Isolate(controlPort, |
pauseCapability: capabilities[0], |
terminateCapability: capabilities[1])); |
- }; |
- return completer.future; |
- } catch (e, st) { |
- if (readyPort != null) { |
- readyPort.close(); |
+ } else { |
+ completer.completeError(new IsolateSpawnException( |
+ "Internal error: received unexpected message $readyMessage")); |
} |
- return new Future<Isolate>.error(e, st); |
}; |
return completer.future; |
} |