summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Clawsie <brad@b7j0c.org>2026-11-25 14:32:46 -0600
committerBrad Clawsie <brad@b7j0c.org>2026-11-25 14:32:46 -0600
commitdfab0cabdac6603176ab4a5ec58e56d535ceb93b (patch)
tree52ea5ed66b1e5e43074504733cde62172423290f
parent7757056c7a43d4fbd85e3e817237d178bf6b1761 (diff)
fix: learn_21
-rw-r--r--learn_21/src/config.rs10
-rw-r--r--learn_21/tests/load_config.rs4
2 files changed, 8 insertions, 6 deletions
diff --git a/learn_21/src/config.rs b/learn_21/src/config.rs
index e0f21c4..a99441a 100644
--- a/learn_21/src/config.rs
+++ b/learn_21/src/config.rs
@@ -92,11 +92,11 @@ pub fn parse_config(input: &str) -> Result<Config, ConfigError> {
if workers.is_none() {
return Err(ConfigError::MissingField("workers".to_string()));
}
-
- Ok(Config{
- host: host.unwrap(),
- port: port.unwrap().get(),
- workers: workers.unwrap().get(),
+
+ Ok(Config {
+ host: host.ok_or_else(|| ConfigError::MissingField("host".into()))?,
+ port: port.ok_or_else(|| ConfigError::MissingField("port".into()))?.get(),
+ workers: workers.ok_or_else(|| ConfigError::MissingField("workers".into()))?.get(),
})
}
diff --git a/learn_21/tests/load_config.rs b/learn_21/tests/load_config.rs
index 5fc7866..35bc8a0 100644
--- a/learn_21/tests/load_config.rs
+++ b/learn_21/tests/load_config.rs
@@ -18,9 +18,11 @@ fn test_load_config() -> io::Result<()> {
assert!(load_config(&file_path).is_ok_and(|x| x ==
Config{host:"myhost".to_string(), port:1, workers:1}));
+
assert!(matches!(
load_config(std::path::Path::new("/bad/path")),
- Err(ConfigError::Io(Error)),
+ Err(ConfigError::Io(err))
+ if err.kind() == std::io::ErrorKind::NotFound
));
fs::remove_file(&file_path)?;