about summary refs log tree commit diff stats
path: root/pkgs/by-name/mp/mpdpopm/src/storage/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-25 20:44:40 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-25 20:44:40 +0100
commit42cb2a63a8143c3557b9304c3eed6973acbc7405 (patch)
treeaf43e088da415bc7768898dc57f7972389ec04cd /pkgs/by-name/mp/mpdpopm/src/storage/mod.rs
parentmodules/river/keymap: Make media good/bad ratings once mappings (diff)
downloadnixos-config-42cb2a63a8143c3557b9304c3eed6973acbc7405.zip
pkgs/mpdpopm: Switch error handling from snafu to anyhow
This is not a library, as such we can just use anyhow and provide better
and more concise errors to the user.
Diffstat (limited to 'pkgs/by-name/mp/mpdpopm/src/storage/mod.rs')
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/storage/mod.rs103
1 files changed, 19 insertions, 84 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/storage/mod.rs b/pkgs/by-name/mp/mpdpopm/src/storage/mod.rs
index d64f17c1..24d8dcb5 100644
--- a/pkgs/by-name/mp/mpdpopm/src/storage/mod.rs
+++ b/pkgs/by-name/mp/mpdpopm/src/storage/mod.rs
@@ -1,54 +1,11 @@
-use std::path::PathBuf;
-
-use backtrace::Backtrace;
-
-#[derive(Debug)]
-pub enum Error {
-    PlayerStopped,
-    BadPath {
-        pth: PathBuf,
-    },
-    SystemTime {
-        source: std::time::SystemTimeError,
-        back: Backtrace,
-    },
-    Client {
-        source: crate::clients::Error,
-        back: Backtrace,
-    },
-}
-
-impl std::fmt::Display for Error {
-    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
-        match self {
-            Error::PlayerStopped => write!(f, "The MPD player is stopped"),
-            Error::BadPath { pth } => write!(f, "Bad path: {:?}", pth),
-            Error::SystemTime { source, back: _ } => {
-                write!(f, "Couldn't get system time: {}", source)
-            }
-            Error::Client { source, back: _ } => write!(f, "Client error: {}", source),
-        }
-    }
-}
-
-impl std::error::Error for Error {
-    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
-        match &self {
-            Error::SystemTime { source, back: _ } => Some(source),
-            Error::Client { source, back: _ } => Some(source),
-            _ => None,
-        }
-    }
-}
-
-type Result<T> = std::result::Result<T, Error>;
+use anyhow::{Error, Result};
 
 pub mod play_count {
-    use backtrace::Backtrace;
+    use anyhow::Context;
 
     use crate::clients::Client;
 
-    use super::{Error, Result};
+    use super::Result;
 
     pub const STICKER: &str = "unwoundstack.com:playcount";
 
@@ -57,10 +14,8 @@ pub mod play_count {
         match client
             .get_sticker::<usize>(file, STICKER)
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })? {
+            .context("Failed to get sticker from client")?
+        {
             Some(n) => Ok(Some(n)),
             None => Ok(None),
         }
@@ -71,10 +26,7 @@ pub mod play_count {
         client
             .set_sticker(file, STICKER, &format!("{}", play_count))
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })?;
+            .context("Failed to set_sticker on client")?;
 
         Ok(())
     }
@@ -109,11 +61,11 @@ pub mod play_count {
 }
 
 pub mod skipped {
-    use backtrace::Backtrace;
+    use anyhow::Context;
 
     use crate::clients::Client;
 
-    use super::{Error, Result};
+    use super::Result;
 
     const STICKER: &str = "unwoundstack.com:skipped_count";
 
@@ -122,10 +74,8 @@ pub mod skipped {
         match client
             .get_sticker::<usize>(file, STICKER)
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })? {
+            .context("Failed to get_sticker on client")?
+        {
             Some(n) => Ok(Some(n)),
             None => Ok(None),
         }
@@ -136,19 +86,16 @@ pub mod skipped {
         client
             .set_sticker(file, STICKER, &format!("{}", skip_count))
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })
+            .context("Failed to set_sticker on client")
     }
 }
 
 pub mod last_played {
-    use backtrace::Backtrace;
+    use anyhow::Context;
 
     use crate::clients::Client;
 
-    use super::{Error, Result};
+    use super::Result;
 
     pub const STICKER: &str = "unwoundstack.com:lastplayed";
 
@@ -157,10 +104,7 @@ pub mod last_played {
         client
             .get_sticker::<u64>(file, STICKER)
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })
+            .context("Falied to get_sticker on client")
     }
 
     /// Set the last played for a track
@@ -168,20 +112,17 @@ pub mod last_played {
         client
             .set_sticker(file, STICKER, &format!("{}", last_played))
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })?;
+            .context("Failed to set_sticker on client")?;
         Ok(())
     }
 }
 
 pub mod rating_count {
-    use backtrace::Backtrace;
+    use anyhow::Context;
 
     use crate::clients::Client;
 
-    use super::{Error, Result};
+    use super::Result;
 
     pub const STICKER: &str = "unwoundstack.com:ratings_count";
 
@@ -190,10 +131,7 @@ pub mod rating_count {
         client
             .get_sticker::<i8>(file, STICKER)
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })
+            .context("Failed to get_sticker on client")
     }
 
     /// Set the rating count for a track
@@ -201,10 +139,7 @@ pub mod rating_count {
         client
             .set_sticker(file, STICKER, &format!("{}", rating_count))
             .await
-            .map_err(|err| Error::Client {
-                source: err,
-                back: Backtrace::new(),
-            })?;
+            .context("Failed to set_sticker on client")?;
         Ok(())
     }
 }