]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Make it more clear that the number in an error message is a line number
[tablify] / src / lib.rs
index af582d45272207432a0d5de47e6f01be1dcf9938..e20d23d342fe9fffaadc9ef162fde04a70d377f4 100644 (file)
@@ -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(())
     }
@@ -169,7 +174,7 @@ impl<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> Iterator
                     InputLine::Entry(col, instance) => match &mut self.row {
                         None => {
                             return Some(Err(std::io::Error::other(format!(
-                                "{}: Entry with no header",
+                                "line {}: Entry with no header",
                                 n + 1
                             ))))
                         }
@@ -498,11 +503,11 @@ mod tests {
 
         let bad = read_rows(&b" foo"[..]);
         assert!(bad.is_err());
-        assert!(format!("{bad:?}").contains("1: Entry with no header"));
+        assert!(format!("{bad:?}").contains("line 1: Entry with no header"));
 
         let bad2 = read_rows(&b"foo\n\n bar"[..]);
         assert!(bad2.is_err());
-        assert!(format!("{bad2:?}").contains("3: Entry with no header"));
+        assert!(format!("{bad2:?}").contains("line 3: Entry with no header"));
     }
 
     #[test]
@@ -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"));