Skip to content

Commit

Permalink
fix(ws): Songbird would fail if it could not deserialize ws payload. (#…
Browse files Browse the repository at this point in the history
…170)

Receiving a new opcode while connecting to a voice channel was causing the connection to fail, while this was handled correctly elsewhere. Unfortunately, Discord added such a payload during every connection.

This PR moves the logging and conversion to no-op (and log) to catch both locations.
  • Loading branch information
Erk- authored and FelixMcFelix committed Nov 20, 2023
1 parent 5eeeee4 commit c73f498
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio_tungstenite::{
MaybeTlsStream,
WebSocketStream,
};
use tracing::instrument;
use tracing::{debug, instrument};
use url::Url;

pub struct WsStream(WebSocketStream<MaybeTlsStream<TcpStream>>);
Expand Down Expand Up @@ -97,7 +97,16 @@ pub(crate) fn convert_ws_message(message: Option<Message>) -> Result<Option<Even
// The below is safe as we have taken ownership of the inner `String`, and don't
// access it as a `str`/`String` or return it if failure occurs.
Some(Message::Text(mut payload)) =>
unsafe { crate::json::from_str(payload.as_mut_str()) }.map(Some)?,
match unsafe { crate::json::from_str(payload.as_mut_str()) } {
Ok(event) => Some(event),
Err(why) => {
debug!(
"Could not deserialize websocket event, payload: {}, error: {}",
payload, why
);
None
},
},
Some(Message::Binary(bytes)) => {
return Err(Error::UnexpectedBinaryMessage(bytes));
},
Expand Down

0 comments on commit c73f498

Please sign in to comment.