feat: Log failed debug assertions in all configurations

Add `logged_debug_assert` macro logging a warning if a condition is not satisfied, before invoking
`debug_assert!`, and use this macro where `Context` is accessible (i.e. don't change function
signatures for now).
Follow-up to 0359481ba4.
This commit is contained in:
iequidoo
2025-07-11 18:02:31 -03:00
committed by iequidoo
parent 402e42f858
commit 58b99f59f7
6 changed files with 47 additions and 10 deletions

View File

@@ -801,5 +801,17 @@ macro_rules! ensure_and_debug_assert_ne {
};
}
/// Logs a warning if a condition is not satisfied.
/// In non-optimized builds, panics also if so.
#[macro_export]
macro_rules! logged_debug_assert {
($ctx:expr, $cond:expr, $($arg:tt)*) => {
if !$cond {
warn!($ctx, $($arg)*);
}
debug_assert!($cond, $($arg)*);
};
}
#[cfg(test)]
mod tools_tests;