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 Apr 9, 2023
1 parent 4849043 commit 752cae7
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 @@ -10,7 +10,7 @@ use async_tungstenite::{
use futures::{SinkExt, StreamExt, TryStreamExt};
use serde_json::Error as JsonError;
use tokio::time::{timeout, Duration};
use tracing::instrument;
use tracing::{debug, instrument};

pub type WsStream = WebSocketStream<ConnectStream>;

Expand Down Expand Up @@ -114,7 +114,16 @@ impl SenderExt for WsStream {
#[inline]
pub(crate) fn convert_ws_message(message: Option<Message>) -> Result<Option<Event>> {
Ok(match message {
Some(Message::Text(payload)) => serde_json::from_str(&payload).map(Some)?,
Some(Message::Text(payload)) => match serde_json::from_str(&payload) {
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 752cae7

Please sign in to comment.