1use thiserror::Error;
2
3macro_rules! log_on_error {
5 ($a: expr_2021) => {
6 match $a {
7 Ok(value) => value,
8 Err(err) => tracing::error!("{}", LeftError::from(err)),
9 }
10 };
11}
12
13macro_rules! exit_on_error {
15 ($a: expr_2021) => {
16 match $a {
17 Ok(value) => value,
18 Err(err) => {
19 tracing::error!("Exiting due to error: {}", LeftError::from(err));
20 std::process::exit(1);
21 }
22 }
23 };
24}
25
26pub(crate) use exit_on_error;
27pub(crate) use log_on_error;
28
29pub type Result<T> = std::result::Result<T, LeftError>;
30pub type Error = std::result::Result<(), LeftError>;
31
32#[derive(Debug, Error)]
33pub enum LeftError {
34 #[error("IO error: {0}.")]
35 IoError(#[from] std::io::Error),
36 #[error("Nix errno: {0}.")]
37 NixErrno(#[from] nix::errno::Errno),
38 #[error("Xlib error: {0}.")]
39 XlibError(#[from] x11_dl::error::OpenError),
40 #[error("XDG error: {0}.")]
41 XdgBaseDirError(#[from] xdg::BaseDirectoriesError),
42 #[error("Integer conversion overlow error: {0}.")]
43 TryFromIntError(#[from] std::num::TryFromIntError),
44
45 #[error("Given String doesn't match with a command.")]
46 UnmatchingCommand,
47 #[error("No command found for keybind.")]
48 CommandNotFound,
49 #[error("No key found for keybind.")]
50 KeyNotFound,
51 #[error("No modifier found for keybind.")]
52 ModifierNotFound,
53 #[error("No config file found.")]
54 NoConfigFound,
55 #[error("No value set for execution.")]
56 ValueNotFound,
57 #[error("X failed status error.")]
58 XFailedStatus,
59}