@@ -42,6 +42,12 @@ base mixin DartToolingDaemonSupport
42
42
/// Once we connect to dtd, this may be toggled to `true` .
43
43
bool _connectedAppServiceIsSupported = false ;
44
44
45
+ /// Stores service detection errors for diagnostic purposes.
46
+ String ? _serviceDetectionError;
47
+
48
+ /// Stores the last error from getVmServices for diagnostic purposes.
49
+ String ? _vmServicesError;
50
+
45
51
/// Whether to await the disposal of all [VmService] objects in
46
52
/// [activeVmServices] upon server shutdown or loss of DTD connection.
47
53
///
@@ -68,6 +74,8 @@ base mixin DartToolingDaemonSupport
68
74
_dtd = null ;
69
75
_activeLocation = null ;
70
76
_connectedAppServiceIsSupported = false ;
77
+ _serviceDetectionError = null ;
78
+ _vmServicesError = null ;
71
79
72
80
// TODO: determine whether we need to dispose the [inspectorObjectGroup] on
73
81
// the Flutter Widget Inspector for each VM service instance.
@@ -88,8 +96,23 @@ base mixin DartToolingDaemonSupport
88
96
if (dtd == null ) return ;
89
97
if (! _connectedAppServiceIsSupported) return ;
90
98
91
- final vmServiceInfos = (await dtd.getVmServices ()).vmServicesInfos;
92
- if (vmServiceInfos.isEmpty) return ;
99
+ List <VmServiceInfo > vmServiceInfos;
100
+ try {
101
+ vmServiceInfos = (await dtd.getVmServices ()).vmServicesInfos;
102
+ _vmServicesError = null ;
103
+ log (LoggingLevel .debug,
104
+ 'Found ${vmServiceInfos .length } VM service(s)' );
105
+ } catch (e, stack) {
106
+ _vmServicesError = 'Failed to get VM services: $e ' ;
107
+ log (LoggingLevel .error, _vmServicesError! );
108
+ log (LoggingLevel .debug, 'Stack trace: $stack ' );
109
+ return ;
110
+ }
111
+ if (vmServiceInfos.isEmpty) {
112
+ _vmServicesError = 'No VM services available' ;
113
+ log (LoggingLevel .warning, _vmServicesError! );
114
+ return ;
115
+ }
93
116
94
117
for (final vmServiceInfo in vmServiceInfos) {
95
118
final vmServiceUri = vmServiceInfo.uri;
@@ -262,15 +285,26 @@ base mixin DartToolingDaemonSupport
262
285
final dtd = _dtd! ;
263
286
264
287
_connectedAppServiceIsSupported = false ;
288
+ _serviceDetectionError = null ;
265
289
try {
266
290
final registeredServices = await dtd.getRegisteredServices ();
267
- if (registeredServices.dtdServices.contains (
268
- '${ConnectedAppServiceConstants .serviceName }.'
269
- '${ConnectedAppServiceConstants .getVmServices }' ,
270
- )) {
291
+ log (LoggingLevel .debug,
292
+ 'Registered DTD services: ${registeredServices .dtdServices }' );
293
+ final expectedService = '${ConnectedAppServiceConstants .serviceName }.'
294
+ '${ConnectedAppServiceConstants .getVmServices }' ;
295
+ if (registeredServices.dtdServices.contains (expectedService)) {
271
296
_connectedAppServiceIsSupported = true ;
297
+ log (LoggingLevel .debug, 'ConnectedApp service detected successfully' );
298
+ } else {
299
+ _serviceDetectionError =
300
+ 'Service "$expectedService " not found in registered services' ;
301
+ log (LoggingLevel .warning, _serviceDetectionError! );
272
302
}
273
- } catch (_) {}
303
+ } catch (e, stack) {
304
+ _serviceDetectionError = 'Failed to get registered services: $e ' ;
305
+ log (LoggingLevel .error, _serviceDetectionError! );
306
+ log (LoggingLevel .debug, 'Stack trace: $stack ' );
307
+ }
274
308
275
309
if (_connectedAppServiceIsSupported) {
276
310
await _listenForConnectedAppServiceEvents ();
@@ -997,16 +1031,21 @@ base mixin DartToolingDaemonSupport
997
1031
inputSchema: Schema .object (),
998
1032
);
999
1033
1000
- static final _connectedAppsNotSupported = CallToolResult (
1001
- isError: true ,
1002
- content: [
1003
- TextContent (
1004
- text:
1005
- 'A Dart SDK of version 3.9.0-163.0.dev or greater is required to '
1006
- 'connect to Dart and Flutter applications.' ,
1007
- ),
1008
- ],
1009
- )..failureReason = CallToolFailureReason .connectedAppServiceNotSupported;
1034
+ CallToolResult get _connectedAppsNotSupported {
1035
+ String errorText;
1036
+ if (_serviceDetectionError != null ) {
1037
+ errorText = 'ConnectedApp service not available: $_serviceDetectionError ' ;
1038
+ } else {
1039
+ errorText =
1040
+ 'A Dart SDK of version 3.9.0-163.0.dev or greater is required to '
1041
+ 'connect to Dart and Flutter applications.' ;
1042
+ }
1043
+
1044
+ return CallToolResult (
1045
+ isError: true ,
1046
+ content: [TextContent (text: errorText)],
1047
+ )..failureReason = CallToolFailureReason .connectedAppServiceNotSupported;
1048
+ }
1010
1049
1011
1050
static final _dtdNotConnected = CallToolResult (
1012
1051
isError: true ,
@@ -1030,12 +1069,19 @@ base mixin DartToolingDaemonSupport
1030
1069
],
1031
1070
)..failureReason = CallToolFailureReason .dtdAlreadyConnected;
1032
1071
1033
- static final _noActiveDebugSession = CallToolResult (
1034
- content: [
1035
- TextContent (text: 'No active debug session to take a screenshot' ),
1036
- ],
1037
- isError: true ,
1038
- )..failureReason = CallToolFailureReason .noActiveDebugSession;
1072
+ CallToolResult get _noActiveDebugSession {
1073
+ var errorText = 'No VM services available' ;
1074
+ if (_vmServicesError != null ) {
1075
+ errorText += ': $_vmServicesError ' ;
1076
+ } else if (_serviceDetectionError != null ) {
1077
+ errorText += ' (service detection failed: $_serviceDetectionError )' ;
1078
+ }
1079
+
1080
+ return CallToolResult (
1081
+ content: [TextContent (text: errorText)],
1082
+ isError: true ,
1083
+ )..failureReason = CallToolFailureReason .noActiveDebugSession;
1084
+ }
1039
1085
1040
1086
static final _flutterDriverNotRegistered = CallToolResult (
1041
1087
content: [
0 commit comments