From 54269da157d45e385638d0be2337d8a852782b53 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 9 Apr 2026 18:34:41 +0900 Subject: [PATCH] fix(cli): claw state exits 1 when no worker state file exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously 'claw state' printed an error message but exited 0, making it impossible for scripts/CI to detect the absence of state without parsing prose. Now propagates Err() to main() which exits 1 and formats the error correctly for both text and --output-format json modes. Text: 'error: no worker state file found at ... — run a worker first' JSON: {"type":"error","error":"no worker state file found at ..."} --- rust/crates/rusty-claude-cli/src/main.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rust/crates/rusty-claude-cli/src/main.rs b/rust/crates/rusty-claude-cli/src/main.rs index 4015dd0..5f04c7b 100644 --- a/rust/crates/rusty-claude-cli/src/main.rs +++ b/rust/crates/rusty-claude-cli/src/main.rs @@ -1427,16 +1427,16 @@ fn run_worker_state(output_format: CliOutputFormat) -> Result<(), Box { - println!("No worker state file found at {}", state_path.display()) - } - CliOutputFormat::Json => println!( - "{}", - serde_json::json!({"error": "no_state_file", "path": state_path.display().to_string()}) - ), - } - return Ok(()); + // Emit a structured error, then return Err so the process exits 1. + // Callers (scripts, CI) need a non-zero exit to detect "no state" without + // parsing prose output. + // Let the error propagate to main() which will format it correctly + // (prose for text mode, JSON envelope for --output-format json). + return Err(format!( + "no worker state file found at {} — run a worker first", + state_path.display() + ) + .into()); } let raw = std::fs::read_to_string(&state_path)?; match output_format {