aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/particle
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-core/src/particle
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-core/src/particle')
-rw-r--r--azalea-core/src/particle/mod.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/azalea-core/src/particle/mod.rs b/azalea-core/src/particle/mod.rs
index 46f88407..c2fa3337 100644
--- a/azalea-core/src/particle/mod.rs
+++ b/azalea-core/src/particle/mod.rs
@@ -1,5 +1,5 @@
use crate::{BlockPos, Slot};
-use azalea_buf::{McBuf, McBufReadable, McBufVarReadable, McBufWritable};
+use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufWritable};
use std::io::{Read, Write};
#[derive(Debug, Clone, McBuf)]
@@ -153,7 +153,7 @@ pub struct VibrationParticle {
}
impl ParticleData {
- pub fn read_from_particle_id(buf: &mut impl Read, id: u32) -> Result<Self, String> {
+ pub fn read_from_particle_id(buf: &mut impl Read, id: u32) -> Result<Self, BufReadError> {
Ok(match id {
0 => ParticleData::AmbientEntityEffect,
1 => ParticleData::AngryVillager,
@@ -243,13 +243,13 @@ impl ParticleData {
85 => ParticleData::WaxOff,
86 => ParticleData::ElectricSpark,
87 => ParticleData::Scrape,
- _ => return Err(format!("Unknown particle id: {}", id)),
+ _ => return Err(BufReadError::UnexpectedEnumVariant { id: id as i32 }),
})
}
}
impl McBufReadable for ParticleData {
- fn read_from(buf: &mut impl Read) -> Result<Self, String> {
+ fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
let id = u32::var_read_from(buf)?;
ParticleData::read_from_particle_id(buf, id)
}