From 93ec4e579bd9fc3c26216e659a673f9ff64d67bf Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 12 Jul 2024 07:37:46 +0000 Subject: [PATCH] error macro suite Signed-off-by: Jason Volk --- src/core/error.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/core/error.rs b/src/core/error.rs index 8567f303..a9f44dc9 100644 --- a/src/core/error.rs +++ b/src/core/error.rs @@ -15,6 +15,48 @@ use ruma::{ use crate::{debug::panic_str, debug_error, error}; +#[macro_export] +macro_rules! err { + (error!($($args:tt),+)) => {{ + error!($($args),+); + $crate::error::Error::Err(format!($($args),+)) + }}; + + (debug_error!($($args:tt),+)) => {{ + debug_error!($($args),+); + $crate::error::Error::Err(format!($($args),+)) + }}; + + ($variant:ident(error!($($args:tt),+))) => {{ + error!($($args),+); + $crate::error::Error::$variant(format!($($args),+)) + }}; + + ($variant:ident(debug_error!($($args:tt),+))) => {{ + debug_error!($($args),+); + $crate::error::Error::$variant(format!($($args),+)) + }}; + + ($variant:ident(format!($($args:tt),+))) => { + $crate::error::Error::$variant(format!($($args),+)) + }; + + ($variant:ident($($args:tt),+)) => { + $crate::error::Error::$variant(format!($($args),+)) + }; + + ($string:literal$(,)? $($args:tt),*) => { + $crate::error::Error::Err(format!($string, $($args),*)) + }; +} + +#[macro_export] +macro_rules! Err { + ($($args:tt)*) => { + Err($crate::err!($($args)*)) + }; +} + #[derive(thiserror::Error)] pub enum Error { #[error("PANIC!")]