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 4905198869..014042d828 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 @@ -234,15 +234,14 @@ class ResidentWebRunner extends ResidentRunner { throwToolExit( 'Failed to establish connection with Chrome. Try running the application again.\n' 'If this problem persists, please file an issue with the details below:\n$err\n$stackTrace'); + } on AppConnectionException { + throwToolExit( + 'Failed to establish connection with the application instance in Chrome.\n' + 'This can happen if the websocket connection used by the web tooling is ' + 'unabled to correctly establish a connection, for example due to a firewall.' + ); } 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 { if (statusActive) { 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 0696195eaf..ba862ada5b 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 @@ -565,13 +565,13 @@ void main() { await expectation; })); - test('Successfully turns AppInstanceId error into ToolExit', () => testbed.run(() async { + test('Successfully turns AppConnectionException 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'); + throw AppConnectionException('Could not connect to application with appInstanceId: c0ae0750-ee91-11e9-cea6-35d95a968356'); })); return ConnectionResult(mockAppConnection, mockDebugConnection); });