Unverified Commit ae291745 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Handle compilation failures from web application (#38723)

parent 7ed27b51
......@@ -238,12 +238,18 @@ class ResidentWebRunner extends ResidentRunner {
return OperationResult(1, 'Failed to recompile application.');
}
if (supportsServiceProtocol) {
final vmservice.Response reloadResponse = await _vmService.callServiceExtension('hotRestart');
status.stop();
printStatus('Restarted application in ${getElapsedAsMilliseconds(timer.elapsed)}.');
return reloadResponse.type == 'Success'
? OperationResult.ok
: OperationResult(1, reloadResponse.toString());
try {
final vmservice.Response reloadResponse = await _vmService.callServiceExtension('hotRestart');
printStatus('Restarted application in ${getElapsedAsMilliseconds(timer.elapsed)}.');
return reloadResponse.type == 'Success'
? OperationResult.ok
: OperationResult(1, reloadResponse.toString());
} on vmservice.RPCError {
await _webFs.hardRefresh();
return OperationResult(1, 'Page requires full reload');
} finally {
status.stop();
}
}
// If we're not in hot mode, the only way to restart is to reload the tab.
await _webFs.hardRefresh();
......
......@@ -319,23 +319,7 @@ class BuildDaemonCreator {
'--define', 'flutter_tools:shell=flutterWebSdk=$flutterWebSdk',
],
logHandler: (ServerLog serverLog) {
switch (serverLog.level) {
case Level.CONFIG:
case Level.FINE:
case Level.FINER:
case Level.FINEST:
case Level.INFO:
printTrace(serverLog.message);
break;
case Level.SEVERE:
case Level.SHOUT:
printError(
serverLog?.error ?? '',
stackTrace: serverLog.stackTrace != null
? StackTrace.fromString(serverLog?.stackTrace)
: null,
);
}
printTrace(serverLog.message);
},
buildMode: daemon.BuildMode.Manual,
);
......
......@@ -61,6 +61,9 @@ void main() {
when(mockWebFs.runAndDebug()).thenAnswer((Invocation _) async {
return mockDebugConnection;
});
when(mockWebFs.recompile()).thenAnswer((Invocation _) {
return Future<bool>.value(false);
});
when(mockDebugConnection.vmService).thenReturn(mockVmService);
when(mockVmService.onStdoutEvent).thenAnswer((Invocation _) {
return const Stream<Event>.empty();
......@@ -165,6 +168,23 @@ void main() {
expect(result.message, contains('Failed'));
}));
test('Fails on vmservice RpcError', () => testbed.run(() async {
_setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
));
await connectionInfoCompleter.future;
when(mockWebFs.recompile()).thenAnswer((Invocation _) async {
return true;
});
when(mockVmService.callServiceExtension('hotRestart')).thenThrow(RPCError('', 2, '123'));
final OperationResult result = await residentWebRunner.restart(fullRestart: true);
expect(result.code, 1);
expect(result.message, contains('Page requires full reload'));
}));
test('printHelp without details is spoopy', () => testbed.run(() async {
residentWebRunner.printHelp(details: false);
final BufferLogger bufferLogger = logger;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment