From 69f189fd45b410be2db3c77e2a4bfa6d9ad8946d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 31 Mar 2021 09:05:12 +0200 Subject: review --- mumd/src/error.rs | 8 +++++--- mumd/src/network/tcp.rs | 14 ++++++++------ mumd/src/notifications.rs | 8 ++++---- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'mumd') diff --git a/mumd/src/error.rs b/mumd/src/error.rs index 142e806..f7818a1 100644 --- a/mumd/src/error.rs +++ b/mumd/src/error.rs @@ -3,11 +3,13 @@ use mumlib::error::ConfigError; use std::fmt; use tokio::sync::mpsc; +pub type ServerSendError = mpsc::error::SendError>; + pub enum TcpError { NoConnectionInfoReceived, TlsConnectorBuilderError(native_tls::Error), TlsConnectError(native_tls::Error), - SendError(mpsc::error::SendError>), + SendError(ServerSendError), IOError(std::io::Error), } @@ -33,8 +35,8 @@ impl From for TcpError { } } -impl From>> for TcpError { - fn from(e: mpsc::error::SendError>) -> Self { +impl From for TcpError { + fn from(e: ServerSendError) -> Self { TcpError::SendError(e) } } diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index 9b0b68e..5783cc8 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -1,4 +1,4 @@ -use crate::error::TcpError; +use crate::error::{ServerSendError, TcpError}; use crate::network::ConnectionInfo; use crate::state::{State, StatePhase}; use log::*; @@ -225,19 +225,21 @@ async fn send_voice( |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::TCP)), async { loop { - packet_sender.send( + let res: Result<(), ServerSendError> = packet_sender.send( receiver .lock() .await .next() .await - .unwrap() //TODO handle panic - .into()) - .unwrap(); //TODO handle panic + .expect("No audio stream") + .into()); + if matches!(res, Err(_)) { + return res; + } } }, inner_phase_watcher.clone(), - ).await; + ).await.unwrap_or(Ok(()))?; } } diff --git a/mumd/src/notifications.rs b/mumd/src/notifications.rs index e52b909..bccf4dd 100644 --- a/mumd/src/notifications.rs +++ b/mumd/src/notifications.rs @@ -2,8 +2,8 @@ use log::*; pub fn init() { #[cfg(feature = "notifications")] - if libnotify::init("mumd").is_err() { - warn!("Unable to initialize notifications"); + if let Err(e) = libnotify::init("mumd") { + warn!("Unable to initialize notifications: {}", e); } } @@ -11,8 +11,8 @@ pub fn init() { pub fn send(msg: String) -> Option { match libnotify::Notification::new("mumd", Some(msg.as_str()), None).show() { Ok(_) => Some(true), - Err(_) => { - warn!("Unable to send notification"); + Err(e) => { + warn!("Unable to send notification: {}", e); Some(false) } } -- cgit v1.2.1