mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-09 17:44:50 +08:00
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:
@@ -1427,16 +1427,16 @@ fn run_worker_state(output_format: CliOutputFormat) -> Result<(), Box<dyn std::e
|
|||||||
let cwd = env::current_dir()?;
|
let cwd = env::current_dir()?;
|
||||||
let state_path = cwd.join(".claw").join("worker-state.json");
|
let state_path = cwd.join(".claw").join("worker-state.json");
|
||||||
if !state_path.exists() {
|
if !state_path.exists() {
|
||||||
match output_format {
|
// Emit a structured error, then return Err so the process exits 1.
|
||||||
CliOutputFormat::Text => {
|
// Callers (scripts, CI) need a non-zero exit to detect "no state" without
|
||||||
println!("No worker state file found at {}", state_path.display())
|
// parsing prose output.
|
||||||
}
|
// Let the error propagate to main() which will format it correctly
|
||||||
CliOutputFormat::Json => println!(
|
// (prose for text mode, JSON envelope for --output-format json).
|
||||||
"{}",
|
return Err(format!(
|
||||||
serde_json::json!({"error": "no_state_file", "path": state_path.display().to_string()})
|
"no worker state file found at {} — run a worker first",
|
||||||
),
|
state_path.display()
|
||||||
}
|
)
|
||||||
return Ok(());
|
.into());
|
||||||
}
|
}
|
||||||
let raw = std::fs::read_to_string(&state_path)?;
|
let raw = std::fs::read_to_string(&state_path)?;
|
||||||
match output_format {
|
match output_format {
|
||||||
|
|||||||
Reference in New Issue
Block a user