From: Scott Worley Date: Thu, 3 Oct 2024 21:09:41 +0000 (-0700) Subject: Invalid/unknown commands are errors X-Git-Tag: v0.4.0~8 X-Git-Url: http://git.scottworley.com/tablify/commitdiff_plain/b2f318323ffed782b90237e38015d65638848d3d?ds=inline;hp=a411a19d502a2ee8ce16c0cd7f447dac3293cee4 Invalid/unknown commands are errors --- 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"));