From b2f318323ffed782b90237e38015d65638848d3d Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 3 Oct 2024 14:09:41 -0700 Subject: [PATCH 1/1] Invalid/unknown commands are errors --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index af582d4..d974461 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,11 @@ impl Config { .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?; } else if let Some(col) = cmd.strip_prefix("col ") { self.static_columns.push(col.to_owned()); + } else { + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + format!("Unknown command: {cmd}"), + )); } Ok(()) } @@ -518,6 +523,10 @@ mod tests { vec!["foo".to_owned()] ); + let bad_command = read_config(&b"!no such command"[..]); + assert!(bad_command.is_err()); + assert!(format!("{bad_command:?}").contains("Unknown command")); + let bad_num = read_config(&b"!col_threshold foo"[..]); assert!(bad_num.is_err()); assert!(format!("{bad_num:?}").contains("Parse")); -- 2.44.1