From 79de647d2aa3ddfe70fa3450cc066b3ed6c717d7 Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Wed, 2 Oct 2024 11:28:58 +0500 Subject: [PATCH] improve config parse errors, fix nixosModules field for stations --- crates/backend/src/config.rs | 22 +++++++++++----------- flake.nix | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/backend/src/config.rs b/crates/backend/src/config.rs index 785467e..c21d5e8 100644 --- a/crates/backend/src/config.rs +++ b/crates/backend/src/config.rs @@ -88,16 +88,16 @@ impl Default for Config { impl std::str::FromStr for Config { type Err = ConfigError; fn from_str(s: &str) -> Result { - toml::from_str(s).map_err(|_| ConfigError::Parse) + toml::from_str(s).map_err(ConfigError::Parse) } } #[derive(Debug)] pub enum ConfigError { - Parse, + Parse(toml::de::Error), StringParse, - Serialize, - IO, + Serialize(toml::ser::Error), + IO(std::io::Error), } impl std::error::Error for ConfigError {} @@ -105,23 +105,23 @@ impl std::error::Error for ConfigError {} impl std::fmt::Display for ConfigError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - Self::Parse => write!(f, "Failed to parse Config from string"), + Self::Parse(e) => write!(f, "Failed to parse Config from string: {}", e), Self::StringParse => write!(f, "Failed to parse environment variable"), - Self::Serialize => write!(f, "Failed to serialize Config to TOML"), - Self::IO => write!(f, "Failed to write a configuration file"), + Self::Serialize(e) => write!(f, "Failed to serialize Config to TOML: {}", e), + Self::IO(e) => write!(f, "Failed to read or write a configuration file: {}", e), } } } impl From for ConfigError { - fn from(_: toml::ser::Error) -> Self { - ConfigError::Serialize + fn from(err: toml::ser::Error) -> Self { + ConfigError::Serialize(err) } } impl From for ConfigError { - fn from(_: std::io::Error) -> Self { - ConfigError::IO + fn from(err: std::io::Error) -> Self { + ConfigError::IO(err) } } diff --git a/flake.nix b/flake.nix index fc101c6..3fe82ab 100644 --- a/flake.nix +++ b/flake.nix @@ -276,7 +276,7 @@ type = types.str; description = "Station name"; }; - address = mkOption { + host = mkOption { type = types.str; description = "MPD service address"; }; @@ -339,7 +339,7 @@ ${toTOML {inherit (cfg) base server stations;}} ''; in '' - ln -sf ${configFile} ./config.toml + ln -sf ${configFile} ${cfg.dataDir}/config.toml ''; }; }; @@ -367,7 +367,7 @@ { id = "test"; name = "Test"; - address = "127.0.0.1"; + host = "127.0.0.1"; port = 8080; } ];