aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/data.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-08-06 07:22:19 +0000
committerGitHub <noreply@github.com>2022-08-06 02:22:19 -0500
commit5a9fca0ca9cdb46f4b866781f219756c89e2293a (patch)
treeb006e28b91a181734fb9702bb6ec510f5b2af3df /azalea-entity/src/data.rs
parent1d48c3fe34edd4e2295f54bd3d79f81f58c38a8e (diff)
downloadazalea-drasl-5a9fca0ca9cdb46f4b866781f219756c89e2293a.tar.xz
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
Diffstat (limited to 'azalea-entity/src/data.rs')
-rw-r--r--azalea-entity/src/data.rs14
1 files changed, 9 insertions, 5 deletions
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<Self, String> {
+ fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
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<Self, String> {
- let data_type = i32::var_read_from(buf)?;
+ fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
+ 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,
+ })
+ }
})
}
}