mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-10-02 07:21:36 +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_export]
|
||||||
macro_rules! bail {
|
macro_rules! bail {
|
||||||
($msg:literal $(,)?) => {
|
($msg:literal $(,)?) => {
|
||||||
return $crate::private::Err($crate::eyre!($msg).into());
|
return $crate::private::Err($crate::eyre!($msg));
|
||||||
};
|
};
|
||||||
($err:expr $(,)?) => {
|
($err:expr $(,)?) => {
|
||||||
return $crate::private::Err($crate::eyre!($err).into());
|
return $crate::private::Err($crate::eyre!($err));
|
||||||
};
|
};
|
||||||
($fmt:expr, $($arg:tt)*) => {
|
($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 $(,)?) => {
|
($cond:expr, $msg:literal $(,)?) => {
|
||||||
if !$cond {
|
if !$cond {
|
||||||
return $crate::private::Err($crate::eyre!($msg).into());
|
return $crate::private::Err($crate::eyre!($msg));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($cond:expr, $err:expr $(,)?) => {
|
($cond:expr, $err:expr $(,)?) => {
|
||||||
if !$cond {
|
if !$cond {
|
||||||
return $crate::private::Err($crate::eyre!($err).into());
|
return $crate::private::Err($crate::eyre!($err));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($cond:expr, $fmt:expr, $($arg:tt)*) => {
|
($cond:expr, $fmt:expr, $($arg:tt)*) => {
|
||||||
if !$cond {
|
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());
|
assert!(f().is_err());
|
||||||
|
|
||||||
// Tests single-argument `ensure!`
|
let f = || {
|
||||||
let f = || -> Result<()> {
|
|
||||||
ensure!(v + v == 1);
|
ensure!(v + v == 1);
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
@ -49,24 +48,6 @@ fn test_ensure() {
|
|||||||
f().unwrap_err().to_string(),
|
f().unwrap_err().to_string(),
|
||||||
"Condition failed: `v + v == 1`",
|
"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]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user