fix(cli): emit JSON error when session fails to load in --output-format json mode

'failed to restore session' errors from both the path-resolution step
and the JSONL-load step now check output_format and emit:
  {"type":"error","error":"failed to restore session: <detail>"}
instead of bare eprintln prose.

Covers: session not found, corrupt JSONL, permission errors.
This commit is contained in:
YeonGyu-Kim
2026-04-10 05:01:56 +09:00
parent c0248253ac
commit cf129c8793

View File

@@ -2221,7 +2221,17 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu
match resolve_session_reference(&session_path.display().to_string()) { match resolve_session_reference(&session_path.display().to_string()) {
Ok(handle) => handle.path, Ok(handle) => handle.path,
Err(error) => { Err(error) => {
eprintln!("failed to restore session: {error}"); if output_format == CliOutputFormat::Json {
eprintln!(
"{}",
serde_json::json!({
"type": "error",
"error": format!("failed to restore session: {error}"),
})
);
} else {
eprintln!("failed to restore session: {error}");
}
std::process::exit(1); std::process::exit(1);
} }
} }
@@ -2230,7 +2240,17 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu
let session = match Session::load_from_path(&resolved_path) { let session = match Session::load_from_path(&resolved_path) {
Ok(session) => session, Ok(session) => session,
Err(error) => { Err(error) => {
eprintln!("failed to restore session: {error}"); if output_format == CliOutputFormat::Json {
eprintln!(
"{}",
serde_json::json!({
"type": "error",
"error": format!("failed to restore session: {error}"),
})
);
} else {
eprintln!("failed to restore session: {error}");
}
std::process::exit(1); std::process::exit(1);
} }
}; };