From da4242198ff87e5cbc21c7308ab12d9ec3bc99d5 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 9 Apr 2026 21:04:50 +0900 Subject: [PATCH] fix(cli): emit JSON error for unsupported resumed slash commands in JSON mode When claw --output-format json --resume /commit (or /plugins, etc.) encountered an 'unsupported resumed slash command' error, it called eprintln!() and exit(2) directly, bypassing both the main() JSON error handler and the output_format check. Fix: in both the slash-command parse-error path and the run_resume_command Err path, check output_format and emit a structured JSON error: {"type":"error","error":"unsupported resumed slash command","command":"/commit"} Text mode unchanged (still exits 2 with prose to stderr). Addresses the resumed-command parity gap (gaebal-gajae ROADMAP #26 track). 159 CLI tests pass, fmt clean. --- rust/crates/rusty-claude-cli/src/main.rs | 39 ++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/rust/crates/rusty-claude-cli/src/main.rs b/rust/crates/rusty-claude-cli/src/main.rs index 41777a1..e2c156d 100644 --- a/rust/crates/rusty-claude-cli/src/main.rs +++ b/rust/crates/rusty-claude-cli/src/main.rs @@ -2217,11 +2217,33 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu let command = match SlashCommand::parse(raw_command) { Ok(Some(command)) => command, Ok(None) => { - eprintln!("unsupported resumed command: {raw_command}"); + if output_format == CliOutputFormat::Json { + eprintln!( + "{}", + serde_json::json!({ + "type": "error", + "error": format!("unsupported resumed command: {raw_command}"), + "command": raw_command, + }) + ); + } else { + eprintln!("unsupported resumed command: {raw_command}"); + } std::process::exit(2); } Err(error) => { - eprintln!("{error}"); + if output_format == CliOutputFormat::Json { + eprintln!( + "{}", + serde_json::json!({ + "type": "error", + "error": error.to_string(), + "command": raw_command, + }) + ); + } else { + eprintln!("{error}"); + } std::process::exit(2); } }; @@ -2247,7 +2269,18 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu } } Err(error) => { - eprintln!("{error}"); + if output_format == CliOutputFormat::Json { + eprintln!( + "{}", + serde_json::json!({ + "type": "error", + "error": error.to_string(), + "command": raw_command, + }) + ); + } else { + eprintln!("{error}"); + } std::process::exit(2); } }