diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-08-06 07:22:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-06 02:22:19 -0500 |
| commit | 5a9fca0ca9cdb46f4b866781f219756c89e2293a (patch) | |
| tree | b006e28b91a181734fb9702bb6ec510f5b2af3df /azalea-buf/buf-macros/src | |
| parent | 1d48c3fe34edd4e2295f54bd3d79f81f58c38a8e (diff) | |
| download | azalea-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-buf/buf-macros/src')
| -rw-r--r-- | azalea-buf/buf-macros/src/lib.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/azalea-buf/buf-macros/src/lib.rs b/azalea-buf/buf-macros/src/lib.rs index a735a920..25bceef0 100644 --- a/azalea-buf/buf-macros/src/lib.rs +++ b/azalea-buf/buf-macros/src/lib.rs @@ -41,7 +41,7 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt quote! { impl azalea_buf::McBufReadable for #ident { - fn read_from(buf: &mut impl std::io::Read) -> Result<Self, String> { + fn read_from(buf: &mut impl std::io::Read) -> Result<Self, azalea_buf::BufReadError> { #(#read_fields)* Ok(#ident { #(#read_field_names: #read_field_names),* @@ -60,9 +60,14 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt variant_discrim = match &d.1 { syn::Expr::Lit(e) => match &e.lit { syn::Lit::Int(i) => i.base10_parse().unwrap(), - _ => panic!("Error parsing enum discriminant"), + _ => panic!("Error parsing enum discriminant as int"), }, - _ => panic!("Error parsing enum discriminant"), + syn::Expr::Unary(_) => { + panic!("Negative enum discriminants are not supported") + } + _ => { + panic!("Error parsing enum discriminant as literal (is {:?})", d.1) + } } } None => { @@ -76,12 +81,12 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt quote! { impl azalea_buf::McBufReadable for #ident { - fn read_from(buf: &mut impl std::io::Read) -> Result<Self, String> + fn read_from(buf: &mut impl std::io::Read) -> Result<Self, azalea_buf::BufReadError> { let id = azalea_buf::McBufVarReadable::var_read_from(buf)?; match id { #match_contents - _ => Err(format!("Unknown enum variant {}", id)), + _ => Err(azalea_buf::BufReadError::UnexpectedEnumVariant { id: id as i32 }), } } } |
