Skip to content

Commit

Permalink
try to recover from unknown message type
Browse files Browse the repository at this point in the history
  • Loading branch information
github-af committed Jul 11, 2024
1 parent f445283 commit ffc4e17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,16 @@ impl Message {

impl fmt::Display for Message {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let msg_type =
match self.message_type() {
Err(e) => format!("UNKNOWN {e}"),
Ok(t) => t.to_string(),
};
write!(
fmt,
"client {:x} message = {} data = {} byte(s)",
self.client_id(),
self.message_type().map_err(|_| fmt::Error)?,
msg_type,
self.payload_len()
)
}
Expand Down
9 changes: 8 additions & 1 deletion src/receive/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ pub(crate) fn start<F>(receiver: &receive::Receiver<F>) -> Result<(), receive::E
continue;
}

let message_type = message.message_type()?;
let message_type =
match message.message_type() {
Err(e) => {
log::error!("message of UNKNOWN type received ({e}), dropping it");
continue;
}
Ok(mt) => mt,
};

let mut will_end = false;

Expand Down

0 comments on commit ffc4e17

Please sign in to comment.