From 5a9fca0ca9cdb46f4b866781f219756c89e2293a Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sat, 6 Aug 2022 07:22:19 +0000 Subject: Better errors (#14) * make reading use thiserror * finish implementing all the error things * clippy warnings related to ok_or * fix some errors in other places * thiserror in more places * don't use closures in a couple places * errors in writing packet * rip backtraces * change some BufReadError::Custom to UnexpectedEnumVariant * Errors say what packet is bad * error on leftover data and fix it wasn't reading the properties for gameprofile --- azalea-entity/src/data.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'azalea-entity/src') diff --git a/azalea-entity/src/data.rs b/azalea-entity/src/data.rs index c9083893..ff708653 100644 --- a/azalea-entity/src/data.rs +++ b/azalea-entity/src/data.rs @@ -1,4 +1,4 @@ -use azalea_buf::McBufVarReadable; +use azalea_buf::{BufReadError, McBufVarReadable}; use azalea_buf::{McBuf, McBufReadable, McBufWritable}; use azalea_chat::component::Component; use azalea_core::{BlockPos, Direction, Particle, Slot}; @@ -17,7 +17,7 @@ pub struct EntityDataItem { } impl McBufReadable for EntityMetadata { - fn read_from(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let mut metadata = Vec::new(); loop { let index = u8::read_from(buf)?; @@ -70,8 +70,8 @@ pub enum EntityDataValue { } impl McBufReadable for EntityDataValue { - fn read_from(buf: &mut impl Read) -> Result { - let data_type = i32::var_read_from(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let data_type = u32::var_read_from(buf)?; Ok(match data_type { 0 => EntityDataValue::Byte(u8::read_from(buf)?), 1 => EntityDataValue::Int(i32::var_read_from(buf)?), @@ -110,7 +110,11 @@ impl McBufReadable for EntityDataValue { } }), 18 => EntityDataValue::Pose(Pose::read_from(buf)?), - _ => return Err(format!("Unknown entity data type: {}", data_type)), + _ => { + return Err(BufReadError::UnexpectedEnumVariant { + id: data_type as i32, + }) + } }) } } -- cgit v1.2.3