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 --- .../src/packets/status/clientbound_status_response_packet.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'azalea-protocol/src/packets/status') diff --git a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs index 2e4116fa..8724816b 100755 --- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs +++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs @@ -1,5 +1,5 @@ use super::ClientboundStatusPacket; -use azalea_buf::Readable; +use azalea_buf::{BufReadError, Readable}; use azalea_chat::component::Component; use serde::Deserialize; use serde_json::Value; @@ -42,14 +42,11 @@ impl ClientboundStatusResponsePacket { Ok(()) } - pub fn read(buf: &mut impl Read) -> Result { + pub fn read(buf: &mut impl Read) -> Result { let status_string = buf.read_utf()?; - let status_json: Value = - serde_json::from_str(status_string.as_str()).expect("Server status isn't valid JSON"); + let status_json: Value = serde_json::from_str(status_string.as_str())?; - let packet = ClientboundStatusResponsePacket::deserialize(status_json) - .map_err(|e| e.to_string())? - .get(); + let packet = ClientboundStatusResponsePacket::deserialize(status_json)?.get(); Ok(packet) } -- cgit v1.2.3