From cf129c87936796263cbee36ea412c28a857be373 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 10 Apr 2026 05:01:56 +0900 Subject: [PATCH] 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: "} instead of bare eprintln prose. Covers: session not found, corrupt JSONL, permission errors. --- rust/crates/rusty-claude-cli/src/main.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/rust/crates/rusty-claude-cli/src/main.rs b/rust/crates/rusty-claude-cli/src/main.rs index a8e47b1..b399f9a 100644 --- a/rust/crates/rusty-claude-cli/src/main.rs +++ b/rust/crates/rusty-claude-cli/src/main.rs @@ -2221,7 +2221,17 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu match resolve_session_reference(&session_path.display().to_string()) { Ok(handle) => handle.path, 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); } } @@ -2230,7 +2240,17 @@ fn resume_session(session_path: &Path, commands: &[String], output_format: CliOu let session = match Session::load_from_path(&resolved_path) { Ok(session) => session, 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); } };