1use std::ffi::OsStr;
4use std::result::Result as StdResult;
5use std::sync::mpsc::RecvError;
6use std::sync::mpsc::RecvTimeoutError;
7use std::sync::mpsc::SendError;
8use std::sync::mpsc::TryRecvError;
9
10use thiserror::Error;
11
12pub type Result<T> = StdResult<T, Error>;
14
15#[derive(Debug, Error)]
17pub enum Error {
18 #[error("terminal error")]
20 Termwiz(#[source] termwiz::Error),
21
22 #[error("regex error")]
24 Regex(#[from] regex::Error),
25
26 #[error("i/o error")]
28 Io(#[from] std::io::Error),
29
30 #[error("keymap error")]
32 Keymap(#[from] crate::keymap_error::KeymapError),
33
34 #[error("keybinding error")]
36 Binding(#[from] crate::bindings::BindingError),
37
38 #[error(transparent)]
40 Fmt(#[from] std::fmt::Error),
41
42 #[error("channel error")]
44 ChannelRecv(#[from] RecvError),
45
46 #[error("channel error")]
48 ChannelTryRecv(#[from] TryRecvError),
49
50 #[error("channel error")]
52 ChannelRecvTimeout(#[from] RecvTimeoutError),
53
54 #[error("channel error")]
56 ChannelSend,
57
58 #[error("terminfo database not found (is $TERM correct?)")]
60 TerminfoDatabaseMissing,
61
62 #[error("error running command '{command}'")]
64 WithCommand {
65 #[source]
67 error: Box<Self>,
68
69 command: String,
71 },
72
73 #[error("error loading file '{file}'")]
75 WithFile {
76 #[source]
78 error: Box<Self>,
79
80 file: String,
82 },
83}
84
85impl Error {
86 #[cfg(feature = "load_file")]
87 pub(crate) fn with_file(self, file: impl AsRef<str>) -> Self {
88 Self::WithFile {
89 error: Box::new(self),
90 file: file.as_ref().to_owned(),
91 }
92 }
93
94 pub(crate) fn with_command(self, command: impl AsRef<OsStr>) -> Self {
95 Self::WithCommand {
96 error: Box::new(self),
97 command: command.as_ref().to_string_lossy().to_string(),
98 }
99 }
100}
101
102impl<T> From<SendError<T>> for Error {
103 fn from(_send_error: SendError<T>) -> Error {
104 Error::ChannelSend
105 }
106}