aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/mod.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-protocol/src/packets/mod.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-protocol/src/packets/mod.rs')
-rw-r--r--azalea-protocol/src/packets/mod.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs
index 228d7c74..da1631a0 100644
--- a/azalea-protocol/src/packets/mod.rs
+++ b/azalea-protocol/src/packets/mod.rs
@@ -3,7 +3,8 @@ pub mod handshake;
pub mod login;
pub mod status;
-use azalea_buf::{McBufWritable, Readable, Writable};
+use crate::read::ReadPacketError;
+use azalea_buf::{BufReadError, McBufWritable, Readable, Writable};
use std::io::{Read, Write};
pub const PROTOCOL_VERSION: u32 = 760;
@@ -36,15 +37,15 @@ where
fn id(&self) -> u32;
/// Read a packet by its id, ConnectionProtocol, and flow
- fn read(id: u32, buf: &mut impl Read) -> Result<Self, String>;
+ fn read(id: u32, buf: &mut impl Read) -> Result<Self, ReadPacketError>;
fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
}
impl azalea_buf::McBufReadable for ConnectionProtocol {
- fn read_from(buf: &mut impl Read) -> Result<Self, String> {
- ConnectionProtocol::from_i32(buf.read_varint()?)
- .ok_or_else(|| "Invalid intention".to_string())
+ fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
+ let id = buf.read_varint()?;
+ ConnectionProtocol::from_i32(id).ok_or(BufReadError::UnexpectedEnumVariant { id })
}
}