Unverified Commit a2233eab authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] remove all body_might_complete_normally_catch_error ignores (#115184)

* remove all body_might_complete_normally_catch_error ignores

* add a test
parent d7454d55
...@@ -522,16 +522,13 @@ class ProxiedPortForwarder extends DevicePortForwarder { ...@@ -522,16 +522,13 @@ class ProxiedPortForwarder extends DevicePortForwarder {
socket.listen((Uint8List data) { socket.listen((Uint8List data) {
unawaited(connection.sendRequest('proxy.write', <String, Object>{ unawaited(connection.sendRequest('proxy.write', <String, Object>{
'id': id, 'id': id,
}, data) }, data).catchError((Object error, StackTrace stackTrace) {
// TODO(srawlins): Fix this static issue,
// https://github.com/flutter/flutter/issues/105750.
// ignore: body_might_complete_normally_catch_error
.catchError((Object error, StackTrace stackTrace) {
// Log the error, but proceed normally. Network failure should not // Log the error, but proceed normally. Network failure should not
// crash the tool. If this is critical, the place where the connection // crash the tool. If this is critical, the place where the connection
// is being used would crash. // is being used would crash.
_logger.printWarning('Write to remote proxy error: $error'); _logger.printWarning('Write to remote proxy error: $error');
_logger.printTrace('Write to remote proxy error: $error, stack trace: $stackTrace'); _logger.printTrace('Write to remote proxy error: $error, stack trace: $stackTrace');
return null;
})); }));
}); });
_connectedSockets.add(socket); _connectedSockets.add(socket);
...@@ -543,15 +540,12 @@ class ProxiedPortForwarder extends DevicePortForwarder { ...@@ -543,15 +540,12 @@ class ProxiedPortForwarder extends DevicePortForwarder {
// Send a proxy disconnect event just in case. // Send a proxy disconnect event just in case.
unawaited(connection.sendRequest('proxy.disconnect', <String, Object>{ unawaited(connection.sendRequest('proxy.disconnect', <String, Object>{
'id': id, 'id': id,
}) }).catchError((Object error, StackTrace stackTrace) {
// TODO(srawlins): Fix this static issue,
// https://github.com/flutter/flutter/issues/105750.
// ignore: body_might_complete_normally_catch_error
.catchError((Object error, StackTrace stackTrace) {
// Ignore the error here. There might be a race condition when the // Ignore the error here. There might be a race condition when the
// remote end also disconnects. In any case, this request is just to // remote end also disconnects. In any case, this request is just to
// notify the remote end to disconnect and we should not crash when // notify the remote end to disconnect and we should not crash when
// there is an error here. // there is an error here.
return null;
})); }));
_connectedSockets.remove(socket); _connectedSockets.remove(socket);
})); }));
......
...@@ -629,16 +629,19 @@ class HotRunner extends ResidentRunner { ...@@ -629,16 +629,19 @@ class HotRunner extends ResidentRunner {
if (uiIsolatesIds.contains(isolateRef.id)) { if (uiIsolatesIds.contains(isolateRef.id)) {
continue; continue;
} }
operations.add(device.vmService!.service.kill(isolateRef.id!) operations.add(
// TODO(srawlins): Fix this static issue, device.vmService!.service.kill(isolateRef.id!)
// https://github.com/flutter/flutter/issues/105750. // Since we never check the value of this Future, only await its
// ignore: body_might_complete_normally_catch_error // completion, make its type nullable so we can return null when
// catching errors.
.then<vm_service.Success?>((vm_service.Success success) => success)
.catchError((dynamic error, StackTrace stackTrace) { .catchError((dynamic error, StackTrace stackTrace) {
// Do nothing on a SentinelException since it means the isolate // Do nothing on a SentinelException since it means the isolate
// has already been killed. // has already been killed.
// Error code 105 indicates the isolate is not yet runnable, and might // Error code 105 indicates the isolate is not yet runnable, and might
// be triggered if the tool is attempting to kill the asset parsing // be triggered if the tool is attempting to kill the asset parsing
// isolate before it has finished starting up. // isolate before it has finished starting up.
return null;
}, test: (dynamic error) => error is vm_service.SentinelException }, test: (dynamic error) => error is vm_service.SentinelException
|| (error is vm_service.RPCError && error.code == 105))); || (error is vm_service.RPCError && error.code == 105)));
} }
......
...@@ -685,16 +685,13 @@ class BrowserManager { ...@@ -685,16 +685,13 @@ class BrowserManager {
); );
final Completer<BrowserManager> completer = Completer<BrowserManager>(); final Completer<BrowserManager> completer = Completer<BrowserManager>();
unawaited(chrome.onExit.then((int? browserExitCode) { unawaited(chrome.onExit.then<Object?>((int? browserExitCode) {
throwToolExit('${runtime.name} exited with code $browserExitCode before connecting.'); throwToolExit('${runtime.name} exited with code $browserExitCode before connecting.');
}) }).catchError((Object error, StackTrace stackTrace) {
// TODO(srawlins): Fix this static issue,
// https://github.com/flutter/flutter/issues/105750.
// ignore: body_might_complete_normally_catch_error
.catchError((Object error, StackTrace stackTrace) {
if (!completer.isCompleted) { if (!completer.isCompleted) {
completer.completeError(error, stackTrace); completer.completeError(error, stackTrace);
} }
return null;
})); }));
unawaited(future.then((WebSocketChannel webSocket) { unawaited(future.then((WebSocketChannel webSocket) {
if (completer.isCompleted) { if (completer.isCompleted) {
......
...@@ -187,7 +187,7 @@ Future<vm_service.VmService> setUpVmService( ...@@ -187,7 +187,7 @@ Future<vm_service.VmService> setUpVmService(
// Each service registration requires a request to the attached VM service. Since the // Each service registration requires a request to the attached VM service. Since the
// order of these requests does not matter, store each future in a list and await // order of these requests does not matter, store each future in a list and await
// all at the end of this method. // all at the end of this method.
final List<Future<vm_service.Success>> registrationRequests = <Future<vm_service.Success>>[]; final List<Future<vm_service.Success?>> registrationRequests = <Future<vm_service.Success?>>[];
if (reloadSources != null) { if (reloadSources != null) {
vmService.registerServiceCallback('reloadSources', (Map<String, Object?> params) async { vmService.registerServiceCallback('reloadSources', (Map<String, Object?> params) async {
final String isolateId = _validateRpcStringParam('reloadSources', params, 'isolateId'); final String isolateId = _validateRpcStringParam('reloadSources', params, 'isolateId');
...@@ -289,10 +289,8 @@ Future<vm_service.VmService> setUpVmService( ...@@ -289,10 +289,8 @@ Future<vm_service.VmService> setUpVmService(
// thrown if we're already subscribed. // thrown if we're already subscribed.
registrationRequests.add(vmService registrationRequests.add(vmService
.streamListen(vm_service.EventStreams.kExtension) .streamListen(vm_service.EventStreams.kExtension)
// TODO(srawlins): Fix this static issue, .then<vm_service.Success?>((vm_service.Success success) => success)
// https://github.com/flutter/flutter/issues/105750. .catchError((Object? error) => null, test: (Object? error) => error is vm_service.RPCError)
// ignore: body_might_complete_normally_catch_error
.catchError((Object? error) {}, test: (Object? error) => error is vm_service.RPCError)
); );
} }
......
...@@ -88,6 +88,28 @@ void main() { ...@@ -88,6 +88,28 @@ void main() {
expect(fakeSocket.closeCalled, true); expect(fakeSocket.closeCalled, true);
}); });
testWithoutContext('handles errors', () async {
final FakeServerSocket fakeServerSocket = FakeServerSocket(200);
final ProxiedPortForwarder portForwarder = ProxiedPortForwarder(
FakeDaemonConnection(
handledRequests: <String, Object?>{
'proxy.connect': '1', // id
},
),
logger: bufferLogger,
createSocketServer: (Logger logger, int? hostPort) async =>
fakeServerSocket,
);
final int result = await portForwarder.forward(100);
expect(result, 200);
final FakeSocket fakeSocket = FakeSocket();
fakeServerSocket.controller.add(fakeSocket);
fakeSocket.controller.add(Uint8List.fromList(<int>[1, 2, 3]));
await pumpEventQueue();
});
testWithoutContext('forwards the port from the remote end with device id', () async { testWithoutContext('forwards the port from the remote end with device id', () async {
final FakeServerSocket fakeServerSocket = FakeServerSocket(400); final FakeServerSocket fakeServerSocket = FakeServerSocket(400);
final ProxiedPortForwarder portForwarder = ProxiedPortForwarder( final ProxiedPortForwarder portForwarder = ProxiedPortForwarder(
...@@ -321,3 +343,33 @@ class FakeSocket extends Fake implements Socket { ...@@ -321,3 +343,33 @@ class FakeSocket extends Fake implements Socket {
@override @override
void destroy() {} void destroy() {}
} }
class FakeDaemonConnection extends Fake implements DaemonConnection {
FakeDaemonConnection({
this.handledRequests = const <String, Object?>{},
this.daemonEventStreams = const <String, List<DaemonEventData>>{},
});
/// Mapping of method name to returned object from the [sendRequest] method.
final Map<String, Object?> handledRequests;
final Map<String, List<DaemonEventData>> daemonEventStreams;
@override
Stream<DaemonEventData> listenToEvent(String eventToListen) {
final List<DaemonEventData>? iterable = daemonEventStreams[eventToListen];
if (iterable != null) {
return Stream<DaemonEventData>.fromIterable(iterable);
}
return const Stream<DaemonEventData>.empty();
}
@override
Future<Object?> sendRequest(String method, [Object? params, List<int>? binary]) async {
final Object? response = handledRequests[method];
if (response != null) {
return response;
}
throw Exception('"$method" request failed');
}
}
...@@ -297,11 +297,10 @@ Future<ProcessTestResult> runFlutter( ...@@ -297,11 +297,10 @@ Future<ProcessTestResult> runFlutter(
} }
process.stdin.write('q'); process.stdin.write('q');
return -1; // discarded return -1; // discarded
}) }).catchError((Object error) {
// TODO(srawlins): Fix this static issue, // ignore errors here, they will be reported on the next line
// https://github.com/flutter/flutter/issues/105750. return -1; // discarded
// ignore: body_might_complete_normally_catch_error }));
.catchError((Object error) { /* ignore errors here, they will be reported on the next line */ }));
final int exitCode = await process.exitCode; final int exitCode = await process.exitCode;
if (streamingLogs) { if (streamingLogs) {
debugPrint('${stamp()} (process terminated with exit code $exitCode)'); debugPrint('${stamp()} (process terminated with exit code $exitCode)');
......
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