mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-11 02:24:49 +08:00
fix(cli): emit JSON error for unsupported resumed slash commands in JSON mode
When claw --output-format json --resume <session> /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.
This commit is contained in:
@@ -2217,11 +2217,33 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu
|
|||||||
let command = match SlashCommand::parse(raw_command) {
|
let command = match SlashCommand::parse(raw_command) {
|
||||||
Ok(Some(command)) => command,
|
Ok(Some(command)) => command,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
|
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}");
|
eprintln!("unsupported resumed command: {raw_command}");
|
||||||
|
}
|
||||||
std::process::exit(2);
|
std::process::exit(2);
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
if output_format == CliOutputFormat::Json {
|
||||||
|
eprintln!(
|
||||||
|
"{}",
|
||||||
|
serde_json::json!({
|
||||||
|
"type": "error",
|
||||||
|
"error": error.to_string(),
|
||||||
|
"command": raw_command,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
eprintln!("{error}");
|
eprintln!("{error}");
|
||||||
|
}
|
||||||
std::process::exit(2);
|
std::process::exit(2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2247,7 +2269,18 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
if output_format == CliOutputFormat::Json {
|
||||||
|
eprintln!(
|
||||||
|
"{}",
|
||||||
|
serde_json::json!({
|
||||||
|
"type": "error",
|
||||||
|
"error": error.to_string(),
|
||||||
|
"command": raw_command,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
eprintln!("{error}");
|
eprintln!("{error}");
|
||||||
|
}
|
||||||
std::process::exit(2);
|
std::process::exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user