fix(ws): Songbird would fail if it could not deserialize ws payload. (#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.
This commit is contained in:
Erk
2023-04-09 10:01:50 +02:00
committed by Kyle Simpson
parent 5eeeee4f37
commit c73f4988c8

View File

@@ -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>>);
@@ -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));
},