VectorCraft: An open-source, vector art tool written by scratch in pure Rust
CLI: a malformed JSON Lines entry names its step as well as its line (#3147)
Taha-Mahmoodi49d69d48e57c
diff --git a/apps/vectorcraft-cli/src/main.rs b/apps/vectorcraft-cli/src/main.rsindex 7c23b0c90..431492836 100644--- a/apps/vectorcraft-cli/src/main.rs+++ b/apps/vectorcraft-cli/src/main.rs@@ -386,7 +386,7 @@ fn parse_commands(source: &str, text: &str, first: usize) -> Result<Vec<Step>, Sif entries.len() == MAX_COMMANDS_STEPS {return Err(too_many());}- let v = serde_json::from_str(line).map_err(|e| format!("--commands {source}: line {}: {e}", n + 1))?;+ let v = serde_json::from_str(line).map_err(|e| format!("--commands {source}: step {} (line {}): {e}", first + entries.len(), n + 1))?;entries.push((Some(n + 1), v));}}diff --git a/apps/vectorcraft-cli/tests/cli.rs b/apps/vectorcraft-cli/tests/cli.rsindex 7f3abc94f..40ed4d177 100644--- a/apps/vectorcraft-cli/tests/cli.rs+++ b/apps/vectorcraft-cli/tests/cli.rs@@ -176,7 +176,7 @@ fn run_refuses_malformed_commands_naming_the_step() {bad("params-array.json", br#"[{"command":"select.all","params":[1]}]"#, &["`params` of select.all must be a JSON object"]);bad("typo.json", br#"[{"command":"select.all","param":{}}]"#, &["unknown key `param`"]);bad("broken.json", b"[{\"command\":", &["--commands", "broken.json"]);- bad("lines.jsonl", b"{\"command\":\"select.all\"}\n\n{oops}\n", &["line 3"]);+ bad("lines.jsonl", b"{\"command\":\"select.all\"}\n\n{oops}\n", &["step 2 (line 3)"]);bad("line-array.jsonl", b"{\"command\":\"select.all\"}\n[1]\n", &["step 2 (line 2)"]);bad("latin1.json", b"[{\"command\":\"select.all\",\"params\":{\"name\":\"\xe9\"}}]", &["not UTF-8"]);let many = "{\"command\":\"select.all\"}\n".repeat(100_001);