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