From dfab0cabdac6603176ab4a5ec58e56d535ceb93b Mon Sep 17 00:00:00 2001 From: Brad Clawsie Date: Wed, 25 Nov 2026 14:32:46 -0600 Subject: fix: learn_21 --- learn_21/src/config.rs | 10 +++++----- learn_21/tests/load_config.rs | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'learn_21') 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 { 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)?; -- cgit v1.2.3