improve config parse errors, fix nixosModules field for stations
All checks were successful
nix-build-publish / check (push) Successful in 7m6s
All checks were successful
nix-build-publish / check (push) Successful in 7m6s
This commit is contained in:
parent
ce71c0429a
commit
79de647d2a
@ -88,16 +88,16 @@ impl Default for Config {
|
|||||||
impl std::str::FromStr for Config {
|
impl std::str::FromStr for Config {
|
||||||
type Err = ConfigError;
|
type Err = ConfigError;
|
||||||
fn from_str(s: &str) -> Result<Self, ConfigError> {
|
fn from_str(s: &str) -> Result<Self, ConfigError> {
|
||||||
toml::from_str(s).map_err(|_| ConfigError::Parse)
|
toml::from_str(s).map_err(ConfigError::Parse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
Parse,
|
Parse(toml::de::Error),
|
||||||
StringParse,
|
StringParse,
|
||||||
Serialize,
|
Serialize(toml::ser::Error),
|
||||||
IO,
|
IO(std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for ConfigError {}
|
impl std::error::Error for ConfigError {}
|
||||||
@ -105,23 +105,23 @@ impl std::error::Error for ConfigError {}
|
|||||||
impl std::fmt::Display for ConfigError {
|
impl std::fmt::Display for ConfigError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self {
|
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::StringParse => write!(f, "Failed to parse environment variable"),
|
||||||
Self::Serialize => write!(f, "Failed to serialize Config to TOML"),
|
Self::Serialize(e) => write!(f, "Failed to serialize Config to TOML: {}", e),
|
||||||
Self::IO => write!(f, "Failed to write a configuration file"),
|
Self::IO(e) => write!(f, "Failed to read or write a configuration file: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<toml::ser::Error> for ConfigError {
|
impl From<toml::ser::Error> for ConfigError {
|
||||||
fn from(_: toml::ser::Error) -> Self {
|
fn from(err: toml::ser::Error) -> Self {
|
||||||
ConfigError::Serialize
|
ConfigError::Serialize(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for ConfigError {
|
impl From<std::io::Error> for ConfigError {
|
||||||
fn from(_: std::io::Error) -> Self {
|
fn from(err: std::io::Error) -> Self {
|
||||||
ConfigError::IO
|
ConfigError::IO(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@
|
|||||||
type = types.str;
|
type = types.str;
|
||||||
description = "Station name";
|
description = "Station name";
|
||||||
};
|
};
|
||||||
address = mkOption {
|
host = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "MPD service address";
|
description = "MPD service address";
|
||||||
};
|
};
|
||||||
@ -339,7 +339,7 @@
|
|||||||
${toTOML {inherit (cfg) base server stations;}}
|
${toTOML {inherit (cfg) base server stations;}}
|
||||||
'';
|
'';
|
||||||
in ''
|
in ''
|
||||||
ln -sf ${configFile} ./config.toml
|
ln -sf ${configFile} ${cfg.dataDir}/config.toml
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -367,7 +367,7 @@
|
|||||||
{
|
{
|
||||||
id = "test";
|
id = "test";
|
||||||
name = "Test";
|
name = "Test";
|
||||||
address = "127.0.0.1";
|
host = "127.0.0.1";
|
||||||
port = 8080;
|
port = 8080;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user