Skip to content

Commit a2233ea

Browse files
[flutter_tools] remove all body_might_complete_normally_catch_error ignores (#115184)
* remove all body_might_complete_normally_catch_error ignores * add a test
1 parent d7454d5 commit a2233ea

File tree

6 files changed

+73
-30
lines changed

6 files changed

+73
-30
lines changed

packages/flutter_tools/lib/src/proxied_devices/devices.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -522,16 +522,13 @@ class ProxiedPortForwarder extends DevicePortForwarder {
522522
socket.listen((Uint8List data) {
523523
unawaited(connection.sendRequest('proxy.write', <String, Object>{
524524
'id': id,
525-
}, data)
526-
// TODO(srawlins): Fix this static issue,
527-
// https://github.com/flutter/flutter/issues/105750.
528-
// ignore: body_might_complete_normally_catch_error
529-
.catchError((Object error, StackTrace stackTrace) {
525+
}, data).catchError((Object error, StackTrace stackTrace) {
530526
// Log the error, but proceed normally. Network failure should not
531527
// crash the tool. If this is critical, the place where the connection
532528
// is being used would crash.
533529
_logger.printWarning('Write to remote proxy error: $error');
534530
_logger.printTrace('Write to remote proxy error: $error, stack trace: $stackTrace');
531+
return null;
535532
}));
536533
});
537534
_connectedSockets.add(socket);
@@ -543,15 +540,12 @@ class ProxiedPortForwarder extends DevicePortForwarder {
543540
// Send a proxy disconnect event just in case.
544541
unawaited(connection.sendRequest('proxy.disconnect', <String, Object>{
545542
'id': id,
546-
})
547-
// TODO(srawlins): Fix this static issue,
548-
// https://github.com/flutter/flutter/issues/105750.
549-
// ignore: body_might_complete_normally_catch_error
550-
.catchError((Object error, StackTrace stackTrace) {
543+
}).catchError((Object error, StackTrace stackTrace) {
551544
// Ignore the error here. There might be a race condition when the
552545
// remote end also disconnects. In any case, this request is just to
553546
// notify the remote end to disconnect and we should not crash when
554547
// there is an error here.
548+
return null;
555549
}));
556550
_connectedSockets.remove(socket);
557551
}));

packages/flutter_tools/lib/src/run_hot.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,16 +629,19 @@ class HotRunner extends ResidentRunner {
629629
if (uiIsolatesIds.contains(isolateRef.id)) {
630630
continue;
631631
}
632-
operations.add(device.vmService!.service.kill(isolateRef.id!)
633-
// TODO(srawlins): Fix this static issue,
634-
// https://github.com/flutter/flutter/issues/105750.
635-
// ignore: body_might_complete_normally_catch_error
632+
operations.add(
633+
device.vmService!.service.kill(isolateRef.id!)
634+
// Since we never check the value of this Future, only await its
635+
// completion, make its type nullable so we can return null when
636+
// catching errors.
637+
.then<vm_service.Success?>((vm_service.Success success) => success)
636638
.catchError((dynamic error, StackTrace stackTrace) {
637639
// Do nothing on a SentinelException since it means the isolate
638640
// has already been killed.
639641
// Error code 105 indicates the isolate is not yet runnable, and might
640642
// be triggered if the tool is attempting to kill the asset parsing
641643
// isolate before it has finished starting up.
644+
return null;
642645
}, test: (dynamic error) => error is vm_service.SentinelException
643646
|| (error is vm_service.RPCError && error.code == 105)));
644647
}

packages/flutter_tools/lib/src/test/flutter_web_platform.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,16 +685,13 @@ class BrowserManager {
685685
);
686686
final Completer<BrowserManager> completer = Completer<BrowserManager>();
687687

688-
unawaited(chrome.onExit.then((int? browserExitCode) {
688+
unawaited(chrome.onExit.then<Object?>((int? browserExitCode) {
689689
throwToolExit('${runtime.name} exited with code $browserExitCode before connecting.');
690-
})
691-
// TODO(srawlins): Fix this static issue,
692-
// https://github.com/flutter/flutter/issues/105750.
693-
// ignore: body_might_complete_normally_catch_error
694-
.catchError((Object error, StackTrace stackTrace) {
690+
}).catchError((Object error, StackTrace stackTrace) {
695691
if (!completer.isCompleted) {
696692
completer.completeError(error, stackTrace);
697693
}
694+
return null;
698695
}));
699696
unawaited(future.then((WebSocketChannel webSocket) {
700697
if (completer.isCompleted) {

packages/flutter_tools/lib/src/vmservice.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Future<vm_service.VmService> setUpVmService(
187187
// Each service registration requires a request to the attached VM service. Since the
188188
// order of these requests does not matter, store each future in a list and await
189189
// all at the end of this method.
190-
final List<Future<vm_service.Success>> registrationRequests = <Future<vm_service.Success>>[];
190+
final List<Future<vm_service.Success?>> registrationRequests = <Future<vm_service.Success?>>[];
191191
if (reloadSources != null) {
192192
vmService.registerServiceCallback('reloadSources', (Map<String, Object?> params) async {
193193
final String isolateId = _validateRpcStringParam('reloadSources', params, 'isolateId');
@@ -289,10 +289,8 @@ Future<vm_service.VmService> setUpVmService(
289289
// thrown if we're already subscribed.
290290
registrationRequests.add(vmService
291291
.streamListen(vm_service.EventStreams.kExtension)
292-
// TODO(srawlins): Fix this static issue,
293-
// https://github.com/flutter/flutter/issues/105750.
294-
// ignore: body_might_complete_normally_catch_error
295-
.catchError((Object? error) {}, test: (Object? error) => error is vm_service.RPCError)
292+
.then<vm_service.Success?>((vm_service.Success success) => success)
293+
.catchError((Object? error) => null, test: (Object? error) => error is vm_service.RPCError)
296294
);
297295
}
298296

packages/flutter_tools/test/general.shard/proxied_devices/proxied_devices_test.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ void main() {
8888
expect(fakeSocket.closeCalled, true);
8989
});
9090

91+
testWithoutContext('handles errors', () async {
92+
final FakeServerSocket fakeServerSocket = FakeServerSocket(200);
93+
final ProxiedPortForwarder portForwarder = ProxiedPortForwarder(
94+
FakeDaemonConnection(
95+
handledRequests: <String, Object?>{
96+
'proxy.connect': '1', // id
97+
},
98+
),
99+
logger: bufferLogger,
100+
createSocketServer: (Logger logger, int? hostPort) async =>
101+
fakeServerSocket,
102+
);
103+
final int result = await portForwarder.forward(100);
104+
expect(result, 200);
105+
106+
final FakeSocket fakeSocket = FakeSocket();
107+
fakeServerSocket.controller.add(fakeSocket);
108+
109+
fakeSocket.controller.add(Uint8List.fromList(<int>[1, 2, 3]));
110+
await pumpEventQueue();
111+
});
112+
91113
testWithoutContext('forwards the port from the remote end with device id', () async {
92114
final FakeServerSocket fakeServerSocket = FakeServerSocket(400);
93115
final ProxiedPortForwarder portForwarder = ProxiedPortForwarder(
@@ -321,3 +343,33 @@ class FakeSocket extends Fake implements Socket {
321343
@override
322344
void destroy() {}
323345
}
346+
347+
class FakeDaemonConnection extends Fake implements DaemonConnection {
348+
FakeDaemonConnection({
349+
this.handledRequests = const <String, Object?>{},
350+
this.daemonEventStreams = const <String, List<DaemonEventData>>{},
351+
});
352+
353+
/// Mapping of method name to returned object from the [sendRequest] method.
354+
final Map<String, Object?> handledRequests;
355+
356+
final Map<String, List<DaemonEventData>> daemonEventStreams;
357+
358+
@override
359+
Stream<DaemonEventData> listenToEvent(String eventToListen) {
360+
final List<DaemonEventData>? iterable = daemonEventStreams[eventToListen];
361+
if (iterable != null) {
362+
return Stream<DaemonEventData>.fromIterable(iterable);
363+
}
364+
return const Stream<DaemonEventData>.empty();
365+
}
366+
367+
@override
368+
Future<Object?> sendRequest(String method, [Object? params, List<int>? binary]) async {
369+
final Object? response = handledRequests[method];
370+
if (response != null) {
371+
return response;
372+
}
373+
throw Exception('"$method" request failed');
374+
}
375+
}

packages/flutter_tools/test/integration.shard/overall_experience_test.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,10 @@ Future<ProcessTestResult> runFlutter(
297297
}
298298
process.stdin.write('q');
299299
return -1; // discarded
300-
})
301-
// TODO(srawlins): Fix this static issue,
302-
// https://github.com/flutter/flutter/issues/105750.
303-
// ignore: body_might_complete_normally_catch_error
304-
.catchError((Object error) { /* ignore errors here, they will be reported on the next line */ }));
300+
}).catchError((Object error) {
301+
// ignore errors here, they will be reported on the next line
302+
return -1; // discarded
303+
}));
305304
final int exitCode = await process.exitCode;
306305
if (streamingLogs) {
307306
debugPrint('${stamp()} (process terminated with exit code $exitCode)');

0 commit comments

Comments
 (0)