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-chat/src/component.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'azalea-chat/src/component.rs') diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index d2f687d4..8a038bf0 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -1,6 +1,6 @@ use std::io::{Read, Write}; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; use serde::{de, Deserialize, Deserializer}; use crate::{ @@ -269,11 +269,10 @@ impl<'de> Deserialize<'de> for Component { } impl McBufReadable for Component { - fn read_from(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let string = String::read_from(buf)?; - let json: serde_json::Value = serde_json::from_str(string.as_str()) - .map_err(|_| "Component isn't valid JSON".to_string())?; - let component = Component::deserialize(json).map_err(|e| e.to_string())?; + let json: serde_json::Value = serde_json::from_str(string.as_str())?; + let component = Component::deserialize(json)?; Ok(component) } } -- cgit v1.2.3