From 0dce0c6e30fc9123f0d96c5b6759eede34d7fac7 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 14 Oct 2019 17:28:28 -0700 Subject: [PATCH] catch appInstanceId error from dwds (#42656) --- .../src/build_runner/resident_web_runner.dart | 7 +++++++ .../resident_web_runner_test.dart | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart index 738a3fce05..54e5601ba0 100644 --- a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart @@ -213,6 +213,13 @@ class ResidentWebRunner extends ResidentRunner { throwToolExit('Failed to build application for the Web.'); } on SocketException catch (err) { throwToolExit(err.toString()); + } on StateError catch (err) { + // Handle known state error. + final String message = err.toString(); + if (message.contains('Could not connect to application with appInstanceId')) { + throwToolExit(message); + } + rethrow; } finally { buildStatus.stop(); } diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index bf00dc527d..9bcc9acf0a 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -480,6 +480,25 @@ void main() { await expectation; })); + test('Successfully turns AppInstanceId error into ToolExit', () => testbed.run(() async { + _setupMocks(); + final Completer connectionInfoCompleter = Completer(); + final Completer unhandledErrorCompleter = Completer(); + when(mockWebFs.connect(any)).thenAnswer((Invocation _) async { + unawaited(unhandledErrorCompleter.future.then((void value) { + throw StateError('Could not connect to application with appInstanceId: c0ae0750-ee91-11e9-cea6-35d95a968356'); + })); + return ConnectionResult(mockAppConnection, mockDebugConnection); + }); + + final Future expectation = expectLater(() => residentWebRunner.run( + connectionInfoCompleter: connectionInfoCompleter, + ), throwsA(isInstanceOf())); + + unhandledErrorCompleter.complete(); + await expectation; + })); + test('Rethrows Exception type', () => testbed.run(() async { _setupMocks(); final Completer connectionInfoCompleter = Completer();