mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-11 02:24:49 +08:00
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:
@@ -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) => {
|
||||||
|
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}");
|
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) => {
|
||||||
|
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}");
|
eprintln!("failed to restore session: {error}");
|
||||||
|
}
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user