versio/
errors.rs

1//! Error handling for Versio is all based on `error-chain`.
2
3pub use anyhow::{Context, Error, Result};
4
5// impl<'a, T: ?Sized> From<std::sync::PoisonError<std::sync::MutexGuard<'a, T>>> for Error {
6//   fn from(err: std::sync::PoisonError<std::sync::MutexGuard<'a, T>>) -> Error {
7//     format!("serde yaml error {:?}", err).into()
8//   }
9// }
10//
11// impl From<gpgme::Error> for Error {
12//   fn from(err: gpgme::Error) -> Error { format!("gpgme error {:?}", err).into() }
13// }
14
15#[macro_export]
16macro_rules! err {
17  ($($arg:tt)*) => (std::result::Result::Err(anyhow::anyhow!($($arg)*)))
18}
19
20#[macro_export]
21macro_rules! bad {
22  ($($arg:tt)*) => (anyhow::anyhow!($($arg)*))
23}
24
25#[macro_export]
26macro_rules! bail {
27  ($($arg:tt)*) => (anyhow::bail!($($arg)*))
28}
29
30#[macro_export]
31macro_rules! try_iter {
32  ($arg:expr) => {
33    match $arg {
34      Ok(x) => x,
35      Err(e) => return $crate::either::IterEither2::A(once(Err(e.into())))
36    }
37  };
38}
39
40#[macro_export]
41macro_rules! try_iter3 {
42  ($arg:expr) => {
43    match $arg {
44      Ok(x) => x,
45      Err(e) => return E3::B(once(Err(e.into())))
46    }
47  };
48}
49
50#[macro_export]
51macro_rules! assert_ok {
52  ($t:expr, $($er:tt)*) => {
53    match ($t).then(|| ()).ok_or_else(|| $crate::bad!($($er)*)) {
54      Ok(v) => v,
55      Err(e) => return $crate::err!(e)
56    }
57  }
58}