Skip to content

Commit

Permalink
Revert "Automatically convert to external errors w/ ensure! and bail!" (
Browse files Browse the repository at this point in the history
#133)

Reverts #95
  • Loading branch information
yaahc committed Dec 13, 2023
1 parent d5cad7c commit 32d84dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
12 changes: 6 additions & 6 deletions eyre/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*));
};
}

Expand Down Expand Up @@ -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)*));
}
};
}
Expand Down
21 changes: 1 addition & 20 deletions eyre/tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,14 @@ fn test_ensure() {
};
assert!(f().is_err());

// Tests single-argument `ensure!`
let f = || -> Result<()> {
let f = || {
ensure!(v + v == 1);
Ok(())
};
assert_eq!(
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]
Expand Down

0 comments on commit 32d84dc

Please sign in to comment.