Skip to content

Commit

Permalink
be more explicit about error handling in the ReqSocket recv() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk committed Dec 30, 2024
1 parent 08777a9 commit ebf9403
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,20 @@ impl SocketRecv for ReqSocket {
match self.current_request.take() {
Some(peer_id) => {
if let Some(mut peer) = self.backend.peers.get_mut(&peer_id) {
let message = peer.recv_queue.next().await;
match message {
match peer.recv_queue.next().await {
Some(Ok(Message::Message(mut m))) => {
assert!(m.len() > 1);
assert!(m.pop_front().unwrap().is_empty()); // Ensure that we have delimeter as first part
if m.len() < 2 {
return Err(ZmqError::Other("Invalid message format: too few frames"));
}
if !m.pop_front().unwrap().is_empty() {
return Err(ZmqError::Other("Invalid message format: missing delimiter"));
}
Ok(m)
}
Some(Ok(_)) => todo!(),
Some(Ok(Message::Greeting(_))) | Some(Ok(Message::Command(_))) => {

Check failure on line 91 in src/req.rs

View workflow job for this annotation

GitHub Actions / Check and Lint

unnested or-patterns
// Non-message frames should be ignored by the caller
Err(ZmqError::Other("Received non-message frame"))
}
Some(Err(error)) => Err(error.into()),
None => Err(ZmqError::NoMessage),
}
Expand Down

0 comments on commit ebf9403

Please sign in to comment.