mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-27 04:50:50 +00:00
Revert "Automatically convert to external errors w/ ensure! and bail!" (#133)
Reverts eyre-rs/eyre#95
This commit is contained in:
parent
d5cad7c2a1
commit
32d84dcbac
@ -51,13 +51,13 @@
|
||||
#[macro_export]
|
||||
macro_rules! bail {
|
||||
($msg:literal $(,)?) => {
|
||||
return $crate::private::Err($crate::eyre!($msg).into());
|
||||
return $crate::private::Err($crate::eyre!($msg));
|
||||
};
|
||||
($err:expr $(,)?) => {
|
||||
return $crate::private::Err($crate::eyre!($err).into());
|
||||
return $crate::private::Err($crate::eyre!($err));
|
||||
};
|
||||
($fmt:expr, $($arg:tt)*) => {
|
||||
return $crate::private::Err($crate::eyre!($fmt, $($arg)*).into());
|
||||
return $crate::private::Err($crate::eyre!($fmt, $($arg)*));
|
||||
};
|
||||
}
|
||||
|
||||
@ -114,17 +114,17 @@ macro_rules! ensure {
|
||||
};
|
||||
($cond:expr, $msg:literal $(,)?) => {
|
||||
if !$cond {
|
||||
return $crate::private::Err($crate::eyre!($msg).into());
|
||||
return $crate::private::Err($crate::eyre!($msg));
|
||||
}
|
||||
};
|
||||
($cond:expr, $err:expr $(,)?) => {
|
||||
if !$cond {
|
||||
return $crate::private::Err($crate::eyre!($err).into());
|
||||
return $crate::private::Err($crate::eyre!($err));
|
||||
}
|
||||
};
|
||||
($cond:expr, $fmt:expr, $($arg:tt)*) => {
|
||||
if !$cond {
|
||||
return $crate::private::Err($crate::eyre!($fmt, $($arg)*).into());
|
||||
return $crate::private::Err($crate::eyre!($fmt, $($arg)*));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -40,8 +40,7 @@ fn test_ensure() {
|
||||
};
|
||||
assert!(f().is_err());
|
||||
|
||||
// Tests single-argument `ensure!`
|
||||
let f = || -> Result<()> {
|
||||
let f = || {
|
||||
ensure!(v + v == 1);
|
||||
Ok(())
|
||||
};
|
||||
@ -49,24 +48,6 @@ fn test_ensure() {
|
||||
f().unwrap_err().to_string(),
|
||||
"Condition failed: `v + v == 1`",
|
||||
);
|
||||
|
||||
// Tests automatically converting to external errors with ensure!()
|
||||
let f = || -> Result<(), SomeWrappingErr> {
|
||||
ensure!(false, "this will fail");
|
||||
Ok(())
|
||||
};
|
||||
assert!(f().is_err());
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct SomeWrappingErr {
|
||||
err: eyre::Error,
|
||||
}
|
||||
|
||||
impl From<eyre::Error> for SomeWrappingErr {
|
||||
fn from(err: eyre::Error) -> Self {
|
||||
SomeWrappingErr { err }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user