@@ -17,7 +17,7 @@ use std::{
1717 net:: { TcpListener , TcpStream , ToSocketAddrs } ,
1818} ;
1919
20- use crossbeam_channel:: { Receiver , RecvTimeoutError , Sender } ;
20+ use crossbeam_channel:: { Receiver , RecvError , RecvTimeoutError , Sender } ;
2121
2222pub use crate :: {
2323 error:: { ExtractError , ProtocolError } ,
@@ -158,11 +158,7 @@ impl Connection {
158158 Err ( RecvTimeoutError :: Timeout ) => {
159159 continue ;
160160 }
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 ( ) ) ,
166162 } ;
167163
168164 match msg {
@@ -181,12 +177,14 @@ impl Connection {
181177 continue ;
182178 }
183179 msg => {
184- return Err ( ProtocolError ( format ! ( "expected initialize request, got {msg:?}" ) ) ) ;
180+ return Err ( ProtocolError :: new ( format ! (
181+ "expected initialize request, got {msg:?}"
182+ ) ) ) ;
185183 }
186184 } ;
187185 }
188186
189- return Err ( ProtocolError ( String :: from (
187+ return Err ( ProtocolError :: new ( String :: from (
190188 "Initialization has been aborted during initialization" ,
191189 ) ) ) ;
192190 }
@@ -201,12 +199,10 @@ impl Connection {
201199 self . sender . send ( resp. into ( ) ) . unwrap ( ) ;
202200 match & self . receiver . recv ( ) {
203201 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 ( ) ) ,
210206 }
211207 }
212208
@@ -231,10 +227,8 @@ impl Connection {
231227 Err ( RecvTimeoutError :: Timeout ) => {
232228 continue ;
233229 }
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 ( ) ) ;
238232 }
239233 } ;
240234
@@ -243,14 +237,14 @@ impl Connection {
243237 return Ok ( ( ) ) ;
244238 }
245239 msg => {
246- return Err ( ProtocolError ( format ! (
240+ return Err ( ProtocolError :: new ( format ! (
247241 r#"expected initialized notification, got: {msg:?}"#
248242 ) ) ) ;
249243 }
250244 }
251245 }
252246
253- return Err ( ProtocolError ( String :: from (
247+ return Err ( ProtocolError :: new ( String :: from (
254248 "Initialization has been aborted during initialization" ,
255249 ) ) ) ;
256250 }
@@ -359,9 +353,18 @@ impl Connection {
359353 match & self . receiver . recv_timeout ( std:: time:: Duration :: from_secs ( 30 ) ) {
360354 Ok ( Message :: Notification ( n) ) if n. is_exit ( ) => ( ) ,
361355 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+ ) ) )
363367 }
364- Err ( e) => return Err ( ProtocolError ( format ! ( "unexpected error during shutdown: {e}" ) ) ) ,
365368 }
366369 Ok ( true )
367370 }
@@ -426,7 +429,7 @@ mod tests {
426429
427430 initialize_start_test ( TestCase {
428431 test_messages : vec ! [ notification_msg. clone( ) ] ,
429- expected_resp : Err ( ProtocolError ( format ! (
432+ expected_resp : Err ( ProtocolError :: new ( format ! (
430433 "expected initialize request, got {:?}" ,
431434 notification_msg
432435 ) ) ) ,
0 commit comments