Skip to content
Myr

Fix bail with single str parameter.

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

This was resulting in a missing From conversion, so now just use the anyhow macro also for single parameter bail. Also added small test to verify that that it compiles.

authored by Johan Andersson · committed by Johan Andersson · parent 6fa503d · Browse files · 1 file+24 added−1 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+24 added−1 removed

  • other:+24 added−1 removed

1 file+24 added−1 removed

modified:src/lib.rs+24 added-1 removed
282 unmodified lines
283/// ```284#[macro_export]285macro_rules! bail {286 ($err:expr $(,)?) => {287 return std::result::Result::Err(std::convert::From::from($err));287 return std::result::Result::Err($crate::anyhow!($err));288 };289 ($fmt:expr, $($arg:tt)*) => {290 return std::result::Result::Err($crate::anyhow!($fmt, $($arg)*));291 };
52 unmodified lines
344345 Error::new_adhoc(message, backtrace)346 }347}348349#[cfg(test)]350mod test {351 use super::*;352353 #[test]354 fn anyhow() {355 let error1 = anyhow!("This {}", "works");356 let error2 = anyhow!("This works");357 assert_eq!(error1.to_string(), error2.to_string());358 }359360 #[test]361 fn bail() {362 let f = || -> Result<()> { bail!("This {}", "works") };363 let error1 = f().err().unwrap();364365 let f = || -> Result<()> { bail!("This works") };366 let error2 = f().err().unwrap();367368 assert_eq!(error1.to_string(), error2.to_string());369 }370}