diff options
| author | akbash <akbash@herdr.dev> | 2026-08-25 01:44:10 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-25 01:44:10 +0300 |
| commit | 0e548bcf72671e6e6e661e90192bcb7f2f442032 (patch) | |
| tree | be689fcc2ace48cd6e288998f0bd470307a313a5 /src/cli | |
| parent | cafd9e5dd0e59ecc7551ae066c737f23573460a7 (diff) | |
fix: report agent explain file errors as json (#3023)
refs #3022
Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com>
Diffstat (limited to 'src/cli')
| -rw-r--r-- | src/cli/agent.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/cli/agent.rs b/src/cli/agent.rs index 306c3bd9..42bc5e1c 100644 --- a/src/cli/agent.rs +++ b/src/cli/agent.rs @@ -2,8 +2,8 @@ use std::time::{Duration, Instant}; use crate::api::schema::{ AgentPromptParams, AgentPromptWaitOptions, AgentReadParams, AgentRenameParams, - AgentSendKeysParams, AgentStartParams, AgentTarget, AgentWaitParams, EmptyParams, Method, - PaneProcessInfoParams, PaneTarget, ReadFormat, ReadSource, Request, + AgentSendKeysParams, AgentStartParams, AgentTarget, AgentWaitParams, EmptyParams, ErrorBody, + ErrorResponse, Method, PaneProcessInfoParams, PaneTarget, ReadFormat, ReadSource, Request, }; const AGENT_START_POLL_INTERVAL: Duration = Duration::from_millis(100); @@ -118,7 +118,21 @@ fn agent_explain(args: &[String]) -> std::io::Result<i32> { eprintln!("herdr agent explain --file requires --agent LABEL"); return Ok(2); }; - let content = std::fs::read_to_string(path)?; + let content = match std::fs::read_to_string(&path) { + Ok(content) => content, + Err(err) => { + let response = ErrorResponse { + id: "cli:agent:explain".into(), + error: ErrorBody { + code: "agent_explain_file_read_failed".into(), + message: format!("failed to read agent explain file {path}: {err}"), + }, + }; + let response = serde_json::to_string(&response).map_err(std::io::Error::other)?; + eprintln!("{response}"); + return Ok(1); + } + }; crate::detect::manifest::explain_to_json_value(&crate::detect::manifest::explain_for_label( &agent_label, &content, |
