mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-26 10:47:11 -06:00
#1005: vectorcraft-cli run ends quietly when its reader closes early
`run` reported "Broken pipe" (on Windows "The pipe is being closed") and exited 1 when the reader of its stdout went away, unlike `commands` and the other subcommands, which end quietly. Its step printer now treats a closed pipe as the end of output, not an error: the remaining steps still run (an export is still written), unprinted, and the run exits 0. Other write errors and failing steps still fail. The test runs document.json, a rectangle and an SVG export with stdout closed: status 0, empty stderr, the SVG written; `run --cmd not-a-command` still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # ROADMAP.md
This commit is contained in:
@@ -292,7 +292,21 @@ fn run(args: &[String]) -> Result<(), String> {
|
||||
|
||||
let mut h = Headless::new();
|
||||
let mut out = std::io::stdout().lock();
|
||||
let mut emit = |v: Value| writeln!(out, "{v}").map_err(|e| e.to_string());
|
||||
// A reader that stopped early (a closed pipe) isn't an error, and the batch goes on: its later
|
||||
// steps (an export…) still run, unprinted.
|
||||
let mut closed = false;
|
||||
let mut emit = |v: Value| {
|
||||
if closed {
|
||||
return Ok(());
|
||||
}
|
||||
match writeln!(out, "{v}") {
|
||||
Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => {
|
||||
closed = true;
|
||||
Ok(())
|
||||
}
|
||||
r => r.map_err(|e| e.to_string()),
|
||||
}
|
||||
};
|
||||
if let Some(path) = &input {
|
||||
let r = h.call("app.open", json!({"path": path})).map_err(|e| format!("open {path}: {e}"))?;
|
||||
emit(json!({"step": "open", "path": path, "result": r}))?;
|
||||
|
||||
Reference in New Issue
Block a user