@@ -17,7 +17,7 @@ use std::{
17
17
net:: { TcpListener , TcpStream , ToSocketAddrs } ,
18
18
} ;
19
19
20
- use crossbeam_channel:: { Receiver , RecvTimeoutError , Sender } ;
20
+ use crossbeam_channel:: { Receiver , RecvError , RecvTimeoutError , Sender } ;
21
21
22
22
pub use crate :: {
23
23
error:: { ExtractError , ProtocolError } ,
@@ -158,11 +158,7 @@ impl Connection {
158
158
Err ( RecvTimeoutError :: Timeout ) => {
159
159
continue ;
160
160
}
161
- Err ( e) => {
162
- return Err ( ProtocolError ( format ! (
163
- "expected initialize request, got error: {e}"
164
- ) ) )
165
- }
161
+ Err ( RecvTimeoutError :: Disconnected ) => return Err ( ProtocolError :: disconnected ( ) ) ,
166
162
} ;
167
163
168
164
match msg {
@@ -181,12 +177,14 @@ impl Connection {
181
177
continue ;
182
178
}
183
179
msg => {
184
- return Err ( ProtocolError ( format ! ( "expected initialize request, got {msg:?}" ) ) ) ;
180
+ return Err ( ProtocolError :: new ( format ! (
181
+ "expected initialize request, got {msg:?}"
182
+ ) ) ) ;
185
183
}
186
184
} ;
187
185
}
188
186
189
- return Err ( ProtocolError ( String :: from (
187
+ return Err ( ProtocolError :: new ( String :: from (
190
188
"Initialization has been aborted during initialization" ,
191
189
) ) ) ;
192
190
}
@@ -201,12 +199,10 @@ impl Connection {
201
199
self . sender . send ( resp. into ( ) ) . unwrap ( ) ;
202
200
match & self . receiver . recv ( ) {
203
201
Ok ( Message :: Notification ( n) ) if n. is_initialized ( ) => Ok ( ( ) ) ,
204
- Ok ( msg) => {
205
- Err ( ProtocolError ( format ! ( r#"expected initialized notification, got: {msg:?}"# ) ) )
206
- }
207
- Err ( e) => {
208
- Err ( ProtocolError ( format ! ( "expected initialized notification, got error: {e}" , ) ) )
209
- }
202
+ Ok ( msg) => Err ( ProtocolError :: new ( format ! (
203
+ r#"expected initialized notification, got: {msg:?}"#
204
+ ) ) ) ,
205
+ Err ( RecvError ) => Err ( ProtocolError :: disconnected ( ) ) ,
210
206
}
211
207
}
212
208
@@ -231,10 +227,8 @@ impl Connection {
231
227
Err ( RecvTimeoutError :: Timeout ) => {
232
228
continue ;
233
229
}
234
- Err ( e) => {
235
- return Err ( ProtocolError ( format ! (
236
- "expected initialized notification, got error: {e}" ,
237
- ) ) ) ;
230
+ Err ( RecvTimeoutError :: Disconnected ) => {
231
+ return Err ( ProtocolError :: disconnected ( ) ) ;
238
232
}
239
233
} ;
240
234
@@ -243,14 +237,14 @@ impl Connection {
243
237
return Ok ( ( ) ) ;
244
238
}
245
239
msg => {
246
- return Err ( ProtocolError ( format ! (
240
+ return Err ( ProtocolError :: new ( format ! (
247
241
r#"expected initialized notification, got: {msg:?}"#
248
242
) ) ) ;
249
243
}
250
244
}
251
245
}
252
246
253
- return Err ( ProtocolError ( String :: from (
247
+ return Err ( ProtocolError :: new ( String :: from (
254
248
"Initialization has been aborted during initialization" ,
255
249
) ) ) ;
256
250
}
@@ -359,9 +353,18 @@ impl Connection {
359
353
match & self . receiver . recv_timeout ( std:: time:: Duration :: from_secs ( 30 ) ) {
360
354
Ok ( Message :: Notification ( n) ) if n. is_exit ( ) => ( ) ,
361
355
Ok ( msg) => {
362
- return Err ( ProtocolError ( format ! ( "unexpected message during shutdown: {msg:?}" ) ) )
356
+ return Err ( ProtocolError :: new ( format ! (
357
+ "unexpected message during shutdown: {msg:?}"
358
+ ) ) )
359
+ }
360
+ Err ( RecvTimeoutError :: Timeout ) => {
361
+ return Err ( ProtocolError :: new ( format ! ( "timed out waiting for exit notification" ) ) )
362
+ }
363
+ Err ( RecvTimeoutError :: Disconnected ) => {
364
+ return Err ( ProtocolError :: new ( format ! (
365
+ "channel disconnected waiting for exit notification"
366
+ ) ) )
363
367
}
364
- Err ( e) => return Err ( ProtocolError ( format ! ( "unexpected error during shutdown: {e}" ) ) ) ,
365
368
}
366
369
Ok ( true )
367
370
}
@@ -426,7 +429,7 @@ mod tests {
426
429
427
430
initialize_start_test ( TestCase {
428
431
test_messages : vec ! [ notification_msg. clone( ) ] ,
429
- expected_resp : Err ( ProtocolError ( format ! (
432
+ expected_resp : Err ( ProtocolError :: new ( format ! (
430
433
"expected initialize request, got {:?}" ,
431
434
notification_msg
432
435
) ) ) ,
0 commit comments