diff --git a/crates/byondapi-macros/Cargo.toml b/crates/byondapi-macros/Cargo.toml index 188ac84..cbf260d 100644 --- a/crates/byondapi-macros/Cargo.toml +++ b/crates/byondapi-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "byondapi-macros" -version = "0.1.0" +version = "0.1.1" edition = "2021" description = "Macros for byondapi" license = "MIT" diff --git a/crates/byondapi-macros/src/lib.rs b/crates/byondapi-macros/src/lib.rs index fc7b85a..3fd5d56 100644 --- a/crates/byondapi-macros/src/lib.rs +++ b/crates/byondapi-macros/src/lib.rs @@ -129,14 +129,14 @@ pub fn bind(attr: TokenStream, item: TokenStream) -> TokenStream { match #func_name(#proc_arg_unpacker) { Ok(val) => val, Err(e) => { - let error_string = ::byondapi::value::ByondValue::try_from(e.0).unwrap(); + let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap(); ::byondapi::global_call::call_global_id(byond_string!("stack_trace"), &[error_string]).unwrap(); ::byondapi::value::ByondValue::null() } } } - fn #func_name(#args) -> Result<::byondapi::value::ByondValue, ::byondapi::BindError> + fn #func_name(#args) -> Result<::byondapi::value::ByondValue, ::byondapi::Error> #body }; result.into() @@ -231,13 +231,13 @@ pub fn bind_raw_args(attr: TokenStream, item: TokenStream) -> TokenStream { match #func_name(args) { Ok(val) => val, Err(e) => { - let error_string = ::byondapi::value::ByondValue::try_from(e.0).unwrap(); + let error_string = ::byondapi::value::ByondValue::try_from(::std::format!("{e:?}")).unwrap(); ::byondapi::global_call::call_global_id(byond_string!("stack_trace"), &[error_string]).unwrap(); ::byondapi::value::ByondValue::null() } } } - fn #func_name(args: &mut [::byondapi::value::ByondValue]) -> Result<::byondapi::value::ByondValue, ::byondapi::BindError> + fn #func_name(args: &mut [::byondapi::value::ByondValue]) -> Result<::byondapi::value::ByondValue, ::byondapi::Error> #body }; result.into() diff --git a/crates/byondapi-rs-test/src/lib.rs b/crates/byondapi-rs-test/src/lib.rs index 7c6b163..5c27061 100644 --- a/crates/byondapi-rs-test/src/lib.rs +++ b/crates/byondapi-rs-test/src/lib.rs @@ -91,7 +91,9 @@ fn test_list_pop(mut list: ByondValue) { let element = list.pop_list()?; if list.builtin_length()?.get_number()? as u32 != 4 { - return Err(eyre::eyre!("pop did not actually remove item from list").into()); + return Err(byondapi::Error::BindError(format!( + "pop did not actually remove item from list" + ))); } Ok(element.unwrap()) @@ -113,7 +115,10 @@ fn test_block() { )?; if block.len() != 4 { - return Err(eyre::eyre!("block returned {} turfs when we expected 4", block.len()).into()); + return Err(byondapi::Error::BindError(format!( + "block returned {} turfs when we expected 4", + block.len() + ))); } Ok((block.len() as f32).into()) diff --git a/crates/byondapi-rs/Cargo.toml b/crates/byondapi-rs/Cargo.toml index 3f21740..d14bac5 100644 --- a/crates/byondapi-rs/Cargo.toml +++ b/crates/byondapi-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "byondapi" -version = "0.4.0" +version = "0.4.1" authors = ["tigercat2000 "] edition = "2021" description = "Idiomatic Rust bindings for BYONDAPI" diff --git a/crates/byondapi-rs/src/error.rs b/crates/byondapi-rs/src/error.rs index 31eb329..0cc9324 100644 --- a/crates/byondapi-rs/src/error.rs +++ b/crates/byondapi-rs/src/error.rs @@ -32,6 +32,8 @@ pub enum Error { NonExistentString(CString), /// Thrown when we know byondland failed to create a string UnableToCreateString(CString), + /// Custom error type thrown by binds + BindError(String), } impl Error { @@ -67,6 +69,7 @@ impl std::fmt::Display for Error { Self::UnableToCreateString(string) => { write!(f, "Unable to create string \"{string:#?}\"") } + Self::BindError(string) => write!(f, "{string}"), } } } diff --git a/crates/byondapi-rs/src/lib.rs b/crates/byondapi-rs/src/lib.rs index 3c72c66..c2b26ed 100644 --- a/crates/byondapi-rs/src/lib.rs +++ b/crates/byondapi-rs/src/lib.rs @@ -48,18 +48,6 @@ inventory::collect!(InitFunc); ///Or add a #[byondapi::init] attribute to a function pub struct InitFunc(pub fn() -> ()); -///Custom error type for binds, just to implement From for ? -pub struct BindError(pub String); - -impl From for BindError -where - E: std::fmt::Debug, -{ - fn from(value: E) -> Self { - BindError(format!("{value:#?}")) - } -} - ///This macro caches string ids and returns it instead of doing a stringid lookup everytime ///The macro will panic if the string doesn't already exist on byond init lib ///Example usage: