[flutter_tools] Fallback discovery: Don't crash when an Isolate has no root library (#52354)
This commit is contained in:
@@ -167,7 +167,7 @@ class FallbackDiscovery {
|
||||
throw Exception('Expected Isolate but found Sentinel: $isolateResponse');
|
||||
}
|
||||
final LibraryRef library = (isolateResponse as Isolate).rootLib;
|
||||
if (library.uri.startsWith('package:$packageName')) {
|
||||
if (library != null && library.uri.startsWith('package:$packageName')) {
|
||||
UsageEvent(
|
||||
_kEventName,
|
||||
'success',
|
||||
|
||||
@@ -67,6 +67,31 @@ void main() {
|
||||
), Uri.parse('http://localhost:1'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects assumed port when another isolate has no root library', () async {
|
||||
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
|
||||
return VM()..isolates = <IsolateRef>[
|
||||
IsolateRef()..id = '1',
|
||||
IsolateRef()..id = '2',
|
||||
];
|
||||
});
|
||||
when(mockVmService.getIsolate('1')).thenAnswer((Invocation invocation) async {
|
||||
return Isolate()
|
||||
..rootLib = null;
|
||||
});
|
||||
when(mockVmService.getIsolate('2')).thenAnswer((Invocation invocation) async {
|
||||
return Isolate()
|
||||
..rootLib = (LibraryRef()..uri = 'package:hello/main.dart');
|
||||
});
|
||||
expect(await fallbackDiscovery.discover(
|
||||
assumedDevicePort: 23,
|
||||
deivce: null,
|
||||
hostVmservicePort: 1,
|
||||
packageId: null,
|
||||
usesIpv6: false,
|
||||
packageName: 'hello',
|
||||
), Uri.parse('http://localhost:1'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects mdns discovery if VM service connecton fails due to Sentinel', () async {
|
||||
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
|
||||
return VM()..isolates = <IsolateRef>[
|
||||
|
||||
Reference in New Issue
Block a user