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 ..."}
This commit is contained in:
YeonGyu-Kim
2026-04-09 18:34:41 +09:00
parent f741a42507
commit 54269da157

View File

@@ -1427,16 +1427,16 @@ fn run_worker_state(output_format: CliOutputFormat) -> Result<(), Box<dyn std::e
let cwd = env::current_dir()?;
let state_path = cwd.join(".claw").join("worker-state.json");
if !state_path.exists() {
match output_format {
CliOutputFormat::Text => {
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 {