How do I handle an error when using rust-websocket, so that only this connection fails, and not the entire program?

I am trying to start a Rust WebSocket server. I started with sample code for an asynchronous websocker server .

Every time I get an Io error, for example, when the connection is interrupted, the whole program ends without any error. I changed the code in line 26 of the example to:

 .map_err(|InvalidConnection {error, ..}| { println!("Error:{:?}",error); return error; }) 

This displays an error message, but does not prevent the program from stopping only one connection, and not the failure itself.

The most common error I get:

 Io(Error { repr: Custom(Custom { kind: Other, error: Stream(Error { repr: Custom(Custom { kind: ConnectionAborted, error: StringError("unexpected EOF observed") }) }) }) }) 
+1
asynchronous error-handling websocket rust
source share
1 answer

Well, with some help from the rust of the IRC channel, I found a solution. I just replaced the None error and filtered it.

 .map(Some).or_else(|_| -> Result<_, ()> { Ok(None) }).filter_map(|x| x) 

Perhaps this information will help someone with a similar problem.

0
source share

All Articles