Skip to content
Myr

Add workaround for the bail msg from log4rs crate

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent f99b799 · Browse files · 1 file+22 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+22 added−0 removed

  • other:+22 added−0 removed

1 file+22 added−0 removed

modified:src/macros.rs+22 added
48 unmodified lines
49/// }50/// # Ok(())51/// # }52/// ```53#[cfg(doc)]54#[macro_export]55macro_rules! bail {56 ($msg:literal $(,)?) => {57 return $crate::private::Err($crate::anyhow!($msg))
5 unmodified lines
63 return $crate::private::Err($crate::anyhow!($fmt, $($arg)*))64 };65}6667// Workaround for crates that intentionally contained `{}` in an error message68// prior to https://github.com/dtolnay/anyhow/issues/55 catching the missing69// format args.70#[cfg(not(doc))]71#[macro_export]72macro_rules! bail {73 // https://github.com/estk/log4rs/blob/afa0351af56b3bfd1780389700051d7e4d8bbdc9/src/append/rolling_file/policy/compound/roll/fixed_window.rs#L26174 ("pattern does not contain `{}`") => {75 return $crate::private::Err($crate::Error::msg("pattern does not contain `{}`"))76 };77 ($msg:literal $(,)?) => {78 return $crate::private::Err($crate::anyhow!($msg))79 };80 ($err:expr $(,)?) => {81 return $crate::private::Err($crate::anyhow!($err))82 };83 ($fmt:expr, $($arg:tt)*) => {84 return $crate::private::Err($crate::anyhow!($fmt, $($arg)*))85 };86}8788/// Return early with an error if a condition is not satisfied.89///90/// This macro is equivalent to `if !$cond { return91/// Err(`[`anyhow!($args...)`][anyhow!]`); }`.
115 unmodified lines