lefthk-core 0.3.2

A hotkey daemon for Adventurers
Documentation
use thiserror::Error;

// TODO: Replace with expr_2024
macro_rules! log_on_error {
    ($a: expr_2021) => {
        match $a {
            Ok(value) => value,
            Err(err) => tracing::error!("{}", LeftError::from(err)),
        }
    };
}

// TODO: Repalce with expr_2024
macro_rules! exit_on_error {
    ($a: expr_2021) => {
        match $a {
            Ok(value) => value,
            Err(err) => {
                tracing::error!("Exiting due to error: {}", LeftError::from(err));
                std::process::exit(1);
            }
        }
    };
}

pub(crate) use exit_on_error;
pub(crate) use log_on_error;

pub type Result<T> = std::result::Result<T, LeftError>;
pub type Error = std::result::Result<(), LeftError>;

#[derive(Debug, Error)]
pub enum LeftError {
    #[error("IO error: {0}.")]
    IoError(#[from] std::io::Error),
    #[error("Nix errno: {0}.")]
    NixErrno(#[from] nix::errno::Errno),
    #[error("Xlib error: {0}.")]
    XlibError(#[from] x11_dl::error::OpenError),
    #[error("XDG error: {0}.")]
    XdgBaseDirError(#[from] xdg::BaseDirectoriesError),
    #[error("Integer conversion overlow error: {0}.")]
    TryFromIntError(#[from] std::num::TryFromIntError),

    #[error("Given String doesn't match with a command.")]
    UnmatchingCommand,
    #[error("No command found for keybind.")]
    CommandNotFound,
    #[error("No key found for keybind.")]
    KeyNotFound,
    #[error("No modifier found for keybind.")]
    ModifierNotFound,
    #[error("No config file found.")]
    NoConfigFound,
    #[error("No value set for execution.")]
    ValueNotFound,
    #[error("X failed status error.")]
    XFailedStatus,
}