pnmixer-rust/src/errors.rs

115 lines
2.6 KiB
Rust
Raw Normal View History

2017-06-27 13:56:33 +00:00
use alsa;
2017-07-03 21:38:39 +00:00
use glib;
2017-07-10 07:23:09 +00:00
use libnotify;
2017-06-27 13:56:33 +00:00
use std::convert::From;
2017-06-29 12:25:40 +00:00
use std;
2017-07-05 18:27:16 +00:00
use toml;
2017-06-27 13:56:33 +00:00
2017-06-29 13:50:24 +00:00
2017-06-27 13:56:33 +00:00
error_chain! {
foreign_links {
Alsa(alsa::Error);
2017-07-05 18:27:16 +00:00
IO(std::io::Error);
Toml(toml::de::Error);
2017-07-10 07:23:09 +00:00
Libnotify(libnotify::errors::Error);
2017-06-27 13:56:33 +00:00
}
}
2017-06-29 13:50:24 +00:00
2017-06-27 13:56:33 +00:00
#[macro_export]
macro_rules! try_w {
($expr:expr) => {
try_wr!($expr, ())
};
($expr:expr, $fmt:expr, $($arg:tt)+) => {
try_wr!($expr, (), $fmt, $(arg)+)
2017-06-27 22:23:12 +00:00
};
($expr:expr, $fmt:expr) => {
try_wr!($expr, (), $fmt)
2017-06-27 13:56:33 +00:00
}
}
2017-06-29 13:50:24 +00:00
2017-06-27 13:56:33 +00:00
#[macro_export]
macro_rules! try_wr {
($expr:expr, $ret:expr) => (match $expr {
2017-06-29 12:25:40 +00:00
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
2017-06-27 13:56:33 +00:00
warn!("{:?}", err);
return $ret;
},
});
2017-06-27 22:23:12 +00:00
($expr:expr, $ret:expr, $fmt:expr) => (match $expr {
2017-07-02 16:11:56 +00:00
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
2017-06-27 22:23:12 +00:00
warn!("Original error: {:?}", err);
warn!($fmt);
return $ret;
},
});
2017-06-27 13:56:33 +00:00
($expr:expr, $ret:expr, $fmt:expr, $($arg:tt)+) => (match $expr {
2017-07-02 16:11:56 +00:00
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
2017-06-27 13:56:33 +00:00
warn!("Original error: {:?}", err);
warn!(format!($fmt, $(arg)+));
return $ret;
},
})
}
2017-06-27 22:23:12 +00:00
2017-06-29 13:50:24 +00:00
2017-06-27 22:23:12 +00:00
#[macro_export]
macro_rules! try_r {
($expr:expr, $ret:expr) => (match $expr {
2017-07-02 16:11:56 +00:00
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
2017-06-27 22:23:12 +00:00
return $ret;
},
});
}
2017-06-30 15:24:26 +00:00
#[macro_export]
macro_rules! try_e {
($expr:expr) => {
try_er!($expr, ())
};
($expr:expr, $fmt:expr, $($arg:tt)+) => {
try_er!($expr, (), $fmt, $(arg)+)
};
($expr:expr, $fmt:expr) => {
try_er!($expr, (), $fmt)
}
}
#[macro_export]
macro_rules! try_er {
($expr:expr, $ret:expr) => (match $expr {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
2017-07-05 22:14:24 +00:00
error!("{:?}", err);
::std::process::exit(1);
2017-06-30 15:24:26 +00:00
},
});
($expr:expr, $ret:expr, $fmt:expr) => (match $expr {
2017-07-02 16:11:56 +00:00
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
2017-07-05 22:14:24 +00:00
error!("Original error: {:?}", err);
error!($fmt);
std::process::exit(1);
2017-06-30 15:24:26 +00:00
},
});
($expr:expr, $ret:expr, $fmt:expr, $($arg:tt)+) => (match $expr {
2017-07-02 16:11:56 +00:00
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(err) => {
2017-07-05 22:14:24 +00:00
error!("Original error: {:?}", err);
error!(format!($fmt, $(arg)+));
std::process::exit(1);
2017-06-30 15:24:26 +00:00
},
})
}