Catch failed startup error from build_daemon (#43598)
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 990b1da..1ec5de4 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
@@ -255,6 +255,15 @@
'start or was killed by another process.');
} on SocketException catch (err) {
throwToolExit(err.toString());
+ } on StateError catch (err) {
+ final String message = err.toString();
+ if (message.contains('Unable to start build daemon')) {
+ throwToolExit(
+ 'Failed to start build daemon. The process might have '
+ 'exited unexpectedly during startup. Try running the application '
+ 'again.');
+ }
+ 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 3ba6b31..f6b631c 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
@@ -658,6 +658,26 @@
await expectation;
}));
+ test('Successfully turns failed startup StateError error into ToolExit', () => testbed.run(() async {
+ _setupMocks();
+ final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
+ final Completer<void> unhandledErrorCompleter = Completer<void>();
+ when(mockWebFs.connect(any)).thenAnswer((Invocation _) async {
+ unawaited(unhandledErrorCompleter.future.then((void value) {
+ throw StateError('Unable to start build daemon');
+ }));
+ return ConnectionResult(mockAppConnection, mockDebugConnection);
+ });
+
+ final Future<void> expectation = expectLater(() => residentWebRunner.run(
+ connectionInfoCompleter: connectionInfoCompleter,
+ ), throwsA(isInstanceOf<ToolExit>()));
+
+ unhandledErrorCompleter.complete();
+ await expectation;
+ }));
+
+
test('Rethrows Exception type', () => testbed.run(() async {
_setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();