summaryrefslogtreecommitdiffstats
path: root/src/tmux/error.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-05-06 17:56:06 -0500
committerToby Vincent <tobyv13@gmail.com>2023-05-06 17:56:57 -0500
commitde5b70c5426311ce887e757c7397bed9107c83c0 (patch)
tree8da07e48b7e729122584a3681104396f51c5f54f /src/tmux/error.rs
parentbcdcdb0ada8d13950e22909250b6b6783866535e (diff)
feat: impl tmux session source and parser
Diffstat (limited to 'src/tmux/error.rs')
-rw-r--r--src/tmux/error.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/tmux/error.rs b/src/tmux/error.rs
new file mode 100644
index 0000000..c857e5b
--- /dev/null
+++ b/src/tmux/error.rs
@@ -0,0 +1,49 @@
+#[derive(Debug)]
+pub enum FormatError {
+ Path(String),
+ Timestamp(String),
+}
+
+#[derive(Debug)]
+pub enum Error {
+ IO(std::io::Error),
+ Utf8(std::str::Utf8Error),
+ PathFormat(String),
+ TimestampFormat(String),
+ ParseInt(std::num::ParseIntError),
+ NotFound,
+}
+
+impl std::error::Error for Error {}
+
+impl std::fmt::Display for Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Error::IO(err) => write!(f, "IO error: {}", err),
+ Error::Utf8(err) => write!(f, "Failed to parse UTF8: {}", err),
+
+ Error::PathFormat(s) => write!(f, "Invalid path format: {}", s),
+ Error::TimestampFormat(s) => write!(f, "Invalid timestamp format: {}", s),
+ Error::ParseInt(err) => write!(f, "Failed to parse int: {}", err),
+ Error::NotFound => write!(f, "Tmux session not found"),
+ }
+ }
+}
+
+impl From<std::io::Error> for Error {
+ fn from(value: std::io::Error) -> Self {
+ Self::IO(value)
+ }
+}
+
+impl From<std::str::Utf8Error> for Error {
+ fn from(value: std::str::Utf8Error) -> Self {
+ Self::Utf8(value)
+ }
+}
+
+impl From<std::num::ParseIntError> for Error {
+ fn from(value: std::num::ParseIntError) -> Self {
+ Self::ParseInt(value)
+ }
+}