Skip to content

Commit b023fad

Browse files
[CP-stable]add HttpException to the list of handled exceptions within ResidentWebRunner::run (flutter#153579)
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: What is the link to the issue this cherry-pick is addressing? flutter#153298 ### Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples [CLI tool] When unable to connect to Chrome/Chromium when running a flutter web app, gracefully exit with an error message instead of crashing. ### Impact Description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch) Impacts users locally running Flutter web apps. Users are likely getting noisy crashes when `flutter run` or `flutter debug-adapter` are unable to connect to the flutter web app (perhaps due to a firewall or the user closing the browser before the connection can be made). ### Workaround: Is there a workaround for this issue? N/A. No repro is known. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: What are the steps to validate that this fix works? N/A. No repro is known.
1 parent a1f08ba commit b023fad

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

packages/flutter_tools/lib/src/isolated/resident_web_runner.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
387387
appFailedToStart();
388388
_logger.printError('$error', stackTrace: stackTrace);
389389
throwToolExit(kExitMessage);
390+
} on HttpException catch (error, stackTrace) {
391+
appFailedToStart();
392+
_logger.printError('$error', stackTrace: stackTrace);
393+
throwToolExit(kExitMessage);
390394
} on Exception {
391395
appFailedToStart();
392396
rethrow;

packages/flutter_tools/test/general.shard/resident_web_runner_test.dart

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,59 @@ flutter:
13211321
ProcessManager: () => processManager,
13221322
});
13231323

1324+
testUsingContext('Turns HttpException from ChromeTab::connect into ToolExit', () async {
1325+
final BufferLogger logger = BufferLogger.test();
1326+
final ResidentRunner residentWebRunner = setUpResidentRunner(
1327+
flutterDevice,
1328+
logger: logger,
1329+
);
1330+
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
1331+
setupMocks();
1332+
final FakeChromeConnection chromeConnection = FakeChromeConnection();
1333+
final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher();
1334+
final FakeProcess process = FakeProcess();
1335+
final Chromium chrome = Chromium(
1336+
1,
1337+
chromeConnection,
1338+
chromiumLauncher: chromiumLauncher,
1339+
process: process,
1340+
logger: logger,
1341+
);
1342+
chromiumLauncher.setInstance(chrome);
1343+
1344+
flutterDevice.device = GoogleChromeDevice(
1345+
fileSystem: fileSystem,
1346+
chromiumLauncher: chromiumLauncher,
1347+
logger: logger,
1348+
platform: FakePlatform(),
1349+
processManager: FakeProcessManager.any(),
1350+
);
1351+
webDevFS.baseUri = Uri.parse('http://localhost:8765/app/');
1352+
1353+
final FakeChromeTab chromeTab = FakeChromeTab(
1354+
'index.html',
1355+
connectException: HttpException(
1356+
'Connection closed before full header was received',
1357+
uri: Uri(
1358+
path: 'http://localhost:50094/devtools/page/3036A94908353E86E183B6A40F54104B',
1359+
),
1360+
),
1361+
);
1362+
chromeConnection.tabs.add(chromeTab);
1363+
1364+
await expectLater(
1365+
residentWebRunner.run,
1366+
throwsToolExit(
1367+
message: 'Failed to establish connection with the application instance in Chrome.',
1368+
),
1369+
);
1370+
expect(logger.errorText, contains('HttpException'));
1371+
expect(fakeVmServiceHost.hasRemainingExpectations, isFalse);
1372+
}, overrides: <Type, Generator>{
1373+
FileSystem: () => fileSystem,
1374+
ProcessManager: () => processManager,
1375+
});
1376+
13241377
testUsingContext('Successfully turns AppConnectionException into ToolExit',
13251378
() async {
13261379
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
@@ -1601,14 +1654,21 @@ class FakeChromeConnection extends Fake implements ChromeConnection {
16011654
}
16021655

16031656
class FakeChromeTab extends Fake implements ChromeTab {
1604-
FakeChromeTab(this.url);
1657+
FakeChromeTab(this.url, {
1658+
Exception? connectException,
1659+
}): _connectException = connectException;
16051660

16061661
@override
16071662
final String url;
1663+
1664+
final Exception? _connectException;
16081665
final FakeWipConnection connection = FakeWipConnection();
16091666

16101667
@override
16111668
Future<WipConnection> connect({Function? onError}) async {
1669+
if (_connectException != null) {
1670+
throw _connectException;
1671+
}
16121672
return connection;
16131673
}
16141674
}

0 commit comments

Comments
 (0)