Skip to content

Commit

Permalink
Handle case where no new messages are available
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Jul 17, 2024
1 parent 1ad4f39 commit 3cd3c2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lighthouse-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub enum Error {
Value(#[from] ValueError),
#[error("Server error: {} {} (warnings: {:?})", code, message.clone().unwrap_or_else(|| "(no message)".to_string()), warnings)]
Server { code: i32, message: Option<String>, warnings: Vec<String> },
#[error("No next message available")]
NoNextMessage,
#[error("Custom error")]
Custom(String),
}
Expand Down
6 changes: 5 additions & 1 deletion lighthouse-client/src/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ impl<S> Lighthouse<S>
warn!("Got message without request id from server: {:?}", msg);
}
},
Err(Error::NoNextMessage) => {
info!("No next message available, closing receive loop");
break
},
Err(e) => error!("Bad message: {:?}", e),
}
}
Expand All @@ -104,7 +108,7 @@ impl<S> Lighthouse<S>
#[tracing::instrument(skip(ws_stream))]
async fn receive_raw_from(ws_stream: &mut SplitStream<S>) -> Result<Vec<u8>> {
loop {
let message = ws_stream.next().await.ok_or_else(|| Error::custom("Got no message"))??;
let message = ws_stream.next().await.ok_or_else(|| Error::NoNextMessage)??;
match message {
Message::Binary(bytes) => break Ok(bytes),
// We ignore pings for now
Expand Down

0 comments on commit 3cd3c2b

Please sign in to comment.