Skip to content

Commit 080928d

Browse files
authored
add HttpException to the list of handled exceptions within ResidentWebRunner::run (#153527)
Resolves flutter/flutter#153298, a major crasher of the flutter tool. I plan on cherry-picking this change. In `ResidentWebRunner::run`, many connection-related exceptions are caught, logged, and have `ToolExit`s thrown in their place ([code](https://github.com/flutter/flutter/blob/d23be7a07de3bd7f02db367fce52eff79021df24/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart#L370-L385), [PR that introduced this](flutter/flutter#50895)). However, `HttpException` is not included in this list. See flutter/flutter#153298 (comment) for details if interested.
1 parent a0c0453 commit 080928d

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
@@ -383,6 +383,10 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
383383
appFailedToStart();
384384
_logger.printError('$error', stackTrace: stackTrace);
385385
throwToolExit(kExitMessage);
386+
} on HttpException catch (error, stackTrace) {
387+
appFailedToStart();
388+
_logger.printError('$error', stackTrace: stackTrace);
389+
throwToolExit(kExitMessage);
386390
} on Exception {
387391
appFailedToStart();
388392
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
@@ -1317,6 +1317,59 @@ flutter:
13171317
ProcessManager: () => processManager,
13181318
});
13191319

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

15981651
class FakeChromeTab extends Fake implements ChromeTab {
1599-
FakeChromeTab(this.url);
1652+
FakeChromeTab(this.url, {
1653+
Exception? connectException,
1654+
}): _connectException = connectException;
16001655

16011656
@override
16021657
final String url;
1658+
1659+
final Exception? _connectException;
16031660
final FakeWipConnection connection = FakeWipConnection();
16041661

16051662
@override
16061663
Future<WipConnection> connect({Function? onError}) async {
1664+
if (_connectException != null) {
1665+
throw _connectException;
1666+
}
16071667
return connection;
16081668
}
16091669
}

0 commit comments

Comments
 (0)