@@ -7,6 +7,7 @@ import 'package:flutter_tools/src/base/io.dart';
77import 'package:flutter_tools/src/base/logger.dart' ;
88import 'package:flutter_tools/src/build_info.dart' ;
99import 'package:flutter_tools/src/device_port_forwarder.dart' ;
10+ import 'package:flutter_tools/src/globals.dart' as globals;
1011import 'package:flutter_tools/src/ios/devices.dart' ;
1112import 'package:flutter_tools/src/mdns_discovery.dart' ;
1213import 'package:flutter_tools/src/project.dart' ;
@@ -577,6 +578,30 @@ void main() {
577578 );
578579 });
579580
581+ test ('On macOS, throw tool exit with a helpful message when client throws a SocketException on lookup' , () async {
582+ final MDnsClient client = FakeMDnsClient (
583+ < PtrResourceRecord > [], < String , List <SrvResourceRecord >> {},
584+ socketExceptionOnStart: true );
585+
586+ final MDnsVmServiceDiscovery portDiscovery = MDnsVmServiceDiscovery (
587+ mdnsClient: client,
588+ logger: BufferLogger .test (),
589+ flutterUsage: TestUsage (),
590+ analytics: const NoOpAnalytics (),
591+ );
592+
593+ expect (
594+ portDiscovery.firstMatchingVmService (client),
595+ throwsToolExit (
596+ message:
597+ 'You might be having a permissions issue with your IDE. '
598+ 'Please try going to '
599+ 'System Settings -> Privacy & Security -> Local Network -> '
600+ '[Find your IDE] -> Toggle ON, then restart your phone.' ,
601+ )
602+ );
603+ }, skip: ! globals.platform.isMacOS); // [intended] This tool exit message only works for macOS
604+
580605 testWithoutContext ('Correctly builds VM Service URI with hostVmservicePort == 0' , () async {
581606 final MDnsClient client = FakeMDnsClient (
582607 < PtrResourceRecord > [
@@ -991,13 +1016,15 @@ class FakeMDnsClient extends Fake implements MDnsClient {
9911016 this .txtResponse = const < String , List <TxtResourceRecord >> {},
9921017 this .ipResponse = const < String , List <IPAddressResourceRecord >> {},
9931018 this .osErrorOnStart = false ,
1019+ this .socketExceptionOnStart = false
9941020 });
9951021
9961022 final List <PtrResourceRecord > ptrRecords;
9971023 final Map <String , List <SrvResourceRecord >> srvResponse;
9981024 final Map <String , List <TxtResourceRecord >> txtResponse;
9991025 final Map <String , List <IPAddressResourceRecord >> ipResponse;
10001026 final bool osErrorOnStart;
1027+ final bool socketExceptionOnStart;
10011028
10021029 @override
10031030 Future <void > start ({
@@ -1016,6 +1043,9 @@ class FakeMDnsClient extends Fake implements MDnsClient {
10161043 ResourceRecordQuery query, {
10171044 Duration timeout = const Duration (seconds: 5 ),
10181045 }) {
1046+ if (socketExceptionOnStart) {
1047+ throw const SocketException ('Socket Exception' );
1048+ }
10191049 if (T == PtrResourceRecord && query.fullyQualifiedName == MDnsVmServiceDiscovery .dartVmServiceName) {
10201050 return Stream <PtrResourceRecord >.fromIterable (ptrRecords) as Stream <T >;
10211051 }
0 commit comments