diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-01-25 20:44:40 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-01-25 20:44:40 +0100 |
| commit | 42cb2a63a8143c3557b9304c3eed6973acbc7405 (patch) | |
| tree | af43e088da415bc7768898dc57f7972389ec04cd /pkgs/by-name/mp/mpdpopm/src/config.rs | |
| parent | modules/river/keymap: Make media good/bad ratings once mappings (diff) | |
| download | nixos-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/config.rs')
| -rw-r--r-- | pkgs/by-name/mp/mpdpopm/src/config.rs | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/config.rs b/pkgs/by-name/mp/mpdpopm/src/config.rs index 08509e47..e6c01599 100644 --- a/pkgs/by-name/mp/mpdpopm/src/config.rs +++ b/pkgs/by-name/mp/mpdpopm/src/config.rs @@ -40,9 +40,10 @@ //! bundle-up all the errors, report 'em & urge the user to use the most recent version use crate::vars::{LOCALSTATEDIR, PREFIX}; +use anyhow::{Result, bail}; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; +use std::{env, path::PathBuf}; /// [mpdpopm](crate) can communicate with MPD over either a local Unix socket, or over regular TCP #[derive(Debug, Deserialize, PartialEq, Serialize)] @@ -85,15 +86,6 @@ mod test_connection { } } -impl std::default::Default for Connection { - fn default() -> Self { - Connection::TCP { - host: String::from("localhost"), - port: 6600, - } - } -} - /// This is the most recent `mppopmd` configuration struct. #[derive(Deserialize, Debug, Serialize)] #[serde(default)] @@ -139,31 +131,11 @@ impl Default for Config { } } -#[derive(Debug)] -pub enum Error { - /// Failure to parse - ParseFail { err: Box<dyn std::error::Error> }, -} - -impl std::fmt::Display for Error { - #[allow(unreachable_patterns)] // the _ arm is *currently* unreachable - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - Error::ParseFail { err } => write!(f, "Parse failure: {}", err), - _ => write!(f, "Unknown configuration error"), - } - } -} - -pub type Result<T> = std::result::Result<T, Error>; - pub fn from_str(text: &str) -> Result<Config> { let cfg: Config = match serde_json::from_str(text) { Ok(cfg) => cfg, Err(err_outer) => { - return Err(Error::ParseFail { - err: Box::new(err_outer), - }); + bail!("Failed to parse config: `{}`", err_outer) } }; Ok(cfg) |
