Skip to content

Commit 54269da

Browse files
committed
fix(cli): claw state exits 1 when no worker state file exists
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 ..."}
1 parent f741a42 commit 54269da

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

  • rust/crates/rusty-claude-cli/src

rust/crates/rusty-claude-cli/src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,16 +1427,16 @@ fn run_worker_state(output_format: CliOutputFormat) -> Result<(), Box<dyn std::e
14271427
let cwd = env::current_dir()?;
14281428
let state_path = cwd.join(".claw").join("worker-state.json");
14291429
if !state_path.exists() {
1430-
match output_format {
1431-
CliOutputFormat::Text => {
1432-
println!("No worker state file found at {}", state_path.display())
1433-
}
1434-
CliOutputFormat::Json => println!(
1435-
"{}",
1436-
serde_json::json!({"error": "no_state_file", "path": state_path.display().to_string()})
1437-
),
1438-
}
1439-
return Ok(());
1430+
// Emit a structured error, then return Err so the process exits 1.
1431+
// Callers (scripts, CI) need a non-zero exit to detect "no state" without
1432+
// parsing prose output.
1433+
// Let the error propagate to main() which will format it correctly
1434+
// (prose for text mode, JSON envelope for --output-format json).
1435+
return Err(format!(
1436+
"no worker state file found at {} — run a worker first",
1437+
state_path.display()
1438+
)
1439+
.into());
14401440
}
14411441
let raw = std::fs::read_to_string(&state_path)?;
14421442
match output_format {

0 commit comments

Comments
 (0)