From 5e7f691a605eb61fcbce1a7c37989c94344bf260 Mon Sep 17 00:00:00 2001 From: "(on company time)" <_@_> Date: Tue, 20 Dec 2022 14:46:08 -0600 Subject: [PATCH] :bug: bug: fix constructing errors and forgetting to actually throw the errors --- crates/udp_over_tcp/src/loops.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/udp_over_tcp/src/loops.rs b/crates/udp_over_tcp/src/loops.rs index 1aaa669..989d8cf 100644 --- a/crates/udp_over_tcp/src/loops.rs +++ b/crates/udp_over_tcp/src/loops.rs @@ -2,6 +2,7 @@ use std::{ sync::Arc, }; +use anyhow::bail; use tokio::{ io::{ AsyncReadExt, @@ -26,27 +27,27 @@ pub async fn rx ( let mut tag = [0u8, 0, 0, 0]; let bytes_read = tcp_read.read (&mut tag).await?; if bytes_read != 4 { - anyhow::anyhow! ("loops::rx: Couldn't read 4 bytes for tag"); + bail! ("loops::rx: Couldn't read 4 bytes for tag"); } if tag != [1, 0, 0, 0] { - anyhow::anyhow! ("loops::rx: unexpected tag in framing"); + bail! ("loops::rx: unexpected tag in framing"); } let mut length = [0u8, 0, 0, 0]; let bytes_read = tcp_read.read (&mut length).await?; if bytes_read != 4 { - anyhow::anyhow! ("loops::rx: Couldn't read 4 bytes for tag"); + bail! ("loops::rx: Couldn't read 4 bytes for tag"); } let length = usize::try_from (u32::from_le_bytes (length))?; if length >= 8_192 { - anyhow::anyhow! ("loops::rx: Length too big for UDP packets"); + bail! ("loops::rx: Length too big for UDP packets"); } let mut buf = vec! [0u8; length]; let bytes_read = tcp_read.read_exact (&mut buf).await?; if length != bytes_read { - anyhow::anyhow! ("loops::rx: read_exact failed"); + bail! ("loops::rx: read_exact failed"); } buf.truncate (bytes_read);