diff options
| author | 1zuna <marco@ccbluex.net> | 2024-01-21 00:34:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-20 17:34:54 -0600 |
| commit | 73be589e7ffa826a32e7b88dad17b6b73d7aba3c (patch) | |
| tree | 08952cbd64e5d03d96e2035b9264d6a90d9d1ef1 | |
| parent | fd1c99e74a8a89278522d1d9f9e4493e7a0c0193 (diff) | |
| download | azalea-drasl-73be589e7ffa826a32e7b88dad17b6b73d7aba3c.tar.xz | |
fixes unwrap on write_raw_packet(...) (#128)
| -rw-r--r-- | azalea-client/src/raw_connection.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/azalea-client/src/raw_connection.rs b/azalea-client/src/raw_connection.rs index bcb1ada0..53abd881 100644 --- a/azalea-client/src/raw_connection.rs +++ b/azalea-client/src/raw_connection.rs @@ -10,7 +10,7 @@ use azalea_protocol::{ use bevy_ecs::prelude::*; use parking_lot::Mutex; use thiserror::Error; -use tokio::sync::mpsc; +use tokio::sync::mpsc::{self, error::SendError}; use tracing::error; /// A component for clients that can read and write packets to the server. This @@ -51,6 +51,12 @@ pub enum WritePacketError { }, #[error(transparent)] Encoding(#[from] azalea_protocol::write::PacketEncodeError), + #[error(transparent)] + SendError { + #[from] + #[backtrace] + source: SendError<Vec<u8>>, + }, } impl RawConnection { @@ -88,11 +94,12 @@ impl RawConnection { } } - pub fn write_raw_packet(&self, raw_packet: Vec<u8>) { + pub fn write_raw_packet(&self, raw_packet: Vec<u8>) -> Result<(), WritePacketError> { self.writer .outgoing_packets_sender .send(raw_packet) - .unwrap(); + .map_err(WritePacketError::from)?; + Ok(()) } /// Write the packet with the given state to the server. @@ -106,7 +113,8 @@ impl RawConnection { packet: P, ) -> Result<(), WritePacketError> { let raw_packet = serialize_packet(&packet)?; - self.write_raw_packet(raw_packet); + self.write_raw_packet(raw_packet)?; + Ok(()) } |
