From c73f4988c83d43cb8ee2cf8b3cd6898b9f78c542 Mon Sep 17 00:00:00 2001 From: Erk Date: Sun, 9 Apr 2023 10:01:50 +0200 Subject: [PATCH] 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. --- src/ws.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ws.rs b/src/ws.rs index 5201dcd..1d4755c 100644 --- a/src/ws.rs +++ b/src/ws.rs @@ -14,7 +14,7 @@ use tokio_tungstenite::{ MaybeTlsStream, WebSocketStream, }; -use tracing::instrument; +use tracing::{debug, instrument}; use url::Url; pub struct WsStream(WebSocketStream>); @@ -97,7 +97,16 @@ pub(crate) fn convert_ws_message(message: Option) -> Result - 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)); },