Detect when isolate reload is barred and inform the user (#5582)

This commit is contained in:
John McCutchan 2016-08-24 15:36:17 -07:00 committed by GitHub
parent 95fbb71f0d
commit 09e68c33cc
3 changed files with 20 additions and 5 deletions

View File

@ -1 +1 @@
28e9b3bc49a83cf5d7a1da2222c02f0f929b1909
b2e592592fa070afebd7c062cad245d152a4d370

View File

@ -445,9 +445,18 @@ class HotRunner extends ResidentRunner {
} else {
flutterUsage.sendEvent('hot', 'reload');
}
} catch (errorMessage, st) {
} catch (error, st) {
int errorCode = error['code'];
if (errorCode == Isolate.kIsolateReloadBarred) {
printError('Unable to hot reload app due to an unrecoverable error in '
'the source code. Please address the error and then '
'Use "R" to restart the app.');
flutterUsage.sendEvent('hot', 'reload-barred');
return false;
}
String errorMessage = error['message'];
reloadStatus.stop(showElapsedTime: true);
printError('Hot reload failed:\n$errorMessage\n$st');
printError('Hot reload failed:\ncode = $errorCode\nmessage = $errorMessage\n$st');
return false;
}
await _evictDirtyAssets();

View File

@ -749,12 +749,18 @@ class Isolate extends ServiceObjectOwner {
_upgradeCollection(map, this);
}
static final int kIsolateReloadBarred = 1005;
Future<Map<String, dynamic>> reloadSources() async {
try {
Map<String, dynamic> response = await invokeRpcRaw('_reloadSources');
return response;
} catch (e) {
return new Future<Map<String, dynamic>>.error(e.data['details']);
} on rpc.RpcException catch(e) {
return new Future<Map<String, dynamic>>.error(<String, dynamic>{
'code': e.code,
'message': e.message,
'data': e.data,
});
}
}