@@ -88,38 +88,49 @@ await rpc.InvokeWithCancellationAsync(
88
88
89
89
public async Task ConnectAsync ( Process process , string socketPath , CancellationToken cancellationToken )
90
90
{
91
- using var activity = _activitySource . StartActivity ( ) ;
92
-
93
- _process = process ;
94
-
95
- if ( _rpcTaskCompletionSource . Task . IsCompleted )
91
+ try
96
92
{
97
- throw new InvalidOperationException ( "Already connected to AppHost backchannel." ) ;
93
+ using var activity = _activitySource . StartActivity ( ) ;
94
+
95
+ _process = process ;
96
+
97
+ if ( _rpcTaskCompletionSource . Task . IsCompleted )
98
+ {
99
+ throw new InvalidOperationException ( "Already connected to AppHost backchannel." ) ;
100
+ }
101
+
102
+ logger . LogDebug ( "Connecting to AppHost backchannel at {SocketPath}" , socketPath ) ;
103
+ var socket = new Socket ( AddressFamily . Unix , SocketType . Stream , ProtocolType . Unspecified ) ;
104
+ var endpoint = new UnixDomainSocketEndPoint ( socketPath ) ;
105
+ await socket . ConnectAsync ( endpoint , cancellationToken ) ;
106
+ logger . LogDebug ( "Connected to AppHost backchannel at {SocketPath}" , socketPath ) ;
107
+
108
+ var stream = new NetworkStream ( socket , true ) ;
109
+ var rpc = JsonRpc . Attach ( stream , target ) ;
110
+
111
+ var capabilities = await rpc . InvokeWithCancellationAsync < string [ ] > (
112
+ "GetCapabilitiesAsync" ,
113
+ Array . Empty < object > ( ) ,
114
+ cancellationToken ) ;
115
+
116
+ if ( ! capabilities . Any ( s => s == "baseline.v0" ) )
117
+ {
118
+ throw new AppHostIncompatibleException (
119
+ $ "AppHost is incompatible with the CLI. The AppHost must be updated to a version that supports the baseline.v0 capability.",
120
+ "baseline.v0"
121
+ ) ;
122
+ }
123
+
124
+ _rpcTaskCompletionSource . SetResult ( rpc ) ;
98
125
}
99
-
100
- logger . LogDebug ( "Connecting to AppHost backchannel at {SocketPath}" , socketPath ) ;
101
- var socket = new Socket ( AddressFamily . Unix , SocketType . Stream , ProtocolType . Unspecified ) ;
102
- var endpoint = new UnixDomainSocketEndPoint ( socketPath ) ;
103
- await socket . ConnectAsync ( endpoint , cancellationToken ) ;
104
- logger . LogDebug ( "Connected to AppHost backchannel at {SocketPath}" , socketPath ) ;
105
-
106
- var stream = new NetworkStream ( socket , true ) ;
107
- var rpc = JsonRpc . Attach ( stream , target ) ;
108
-
109
- var capabilities = await rpc . InvokeWithCancellationAsync < string [ ] > (
110
- "GetCapabilitiesAsync" ,
111
- Array . Empty < object > ( ) ,
112
- cancellationToken ) ;
113
-
114
- if ( ! capabilities . Any ( s => s == "baseline.v0" ) )
126
+ catch ( RemoteMethodNotFoundException ex )
115
127
{
128
+ logger . LogError ( ex , "Failed to connect to AppHost backchannel. The AppHost must be updated to a version that supports the baseline.v0 capability." ) ;
116
129
throw new AppHostIncompatibleException (
117
130
$ "AppHost is incompatible with the CLI. The AppHost must be updated to a version that supports the baseline.v0 capability.",
118
131
"baseline.v0"
119
132
) ;
120
133
}
121
-
122
- _rpcTaskCompletionSource . SetResult ( rpc ) ;
123
134
}
124
135
125
136
public async Task < string [ ] > GetPublishersAsync ( CancellationToken cancellationToken )
0 commit comments