use std::ffi::OsStr;
use std::result::Result as StdResult;
use std::sync::mpsc::RecvError;
use std::sync::mpsc::RecvTimeoutError;
use std::sync::mpsc::SendError;
use std::sync::mpsc::TryRecvError;
use thiserror::Error;
pub type Result<T> = StdResult<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("terminal error")]
Termwiz(#[source] termwiz::Error),
#[error("regex error")]
Regex(#[from] regex::Error),
#[error("i/o error")]
Io(#[from] std::io::Error),
#[error(transparent)]
TempfilePersist(#[from] tempfile::PersistError),
#[error("keymap error")]
Keymap(#[from] crate::keymap_error::KeymapError),
#[error("keybinding error")]
Binding(#[from] crate::bindings::BindingError),
#[error(transparent)]
Fmt(#[from] std::fmt::Error),
#[error("channel error")]
ChannelRecv(#[from] RecvError),
#[error("channel error")]
ChannelTryRecv(#[from] TryRecvError),
#[error("channel error")]
ChannelRecvTimeout(#[from] RecvTimeoutError),
#[error("channel error")]
ChannelSend,
#[error("terminfo database not found (is $TERM correct?)")]
TerminfoDatabaseMissing,
#[error("error running command '{command}'")]
WithCommand {
#[source]
error: Box<Self>,
command: String,
},
#[error("error loading file '{file}'")]
WithFile {
#[source]
error: Box<Self>,
file: String,
},
}
impl Error {
#[cfg(feature = "load_file")]
pub(crate) fn with_file(self, file: impl AsRef<str>) -> Self {
Self::WithFile {
error: Box::new(self),
file: file.as_ref().to_owned(),
}
}
pub(crate) fn with_command(self, command: impl AsRef<OsStr>) -> Self {
Self::WithCommand {
error: Box::new(self),
command: command.as_ref().to_string_lossy().to_string(),
}
}
}
impl<T> From<SendError<T>> for Error {
fn from(_send_error: SendError<T>) -> Error {
Error::ChannelSend
}
}