fix(cli-rs): show declared mini errors without their tag

This commit is contained in:
Simon Klee
2026-11-06 03:05:07 +01:00
Unverified
parent 724cf19573
commit 0cf3d21862
2 changed files with 19 additions and 2 deletions
+18 -1
View File
@@ -16,7 +16,7 @@ use super::complete::{Agent, Catalog, Command, Reference};
use super::parts::{Delivery, RunPrompt};
fn error(error: Error) -> String {
error.to_string()
error.tui_message()
}
fn location(directory: &str) -> Option<LocationQueryInput> {
@@ -207,3 +207,20 @@ pub async fn select(client: &Client, session: &str, agent: Option<&str>, model:
call.json(&json!({ "model": model })).map_err(error)?;
client.empty(call).await.map_err(error)
}
#[cfg(test)]
mod tests {
use super::*;
use opencode_api::memory::{Memory, Route};
use std::sync::Arc;
/// A declared error shows its message without its tag, as the TS footer's `formatUnknownError` does.
#[tokio::test]
async fn a_declared_error_shows_its_message() {
let body = json!({ "_tag": "InvalidRequestError", "message": "Unknown agent: nope" });
let memory = Memory::new(vec![Route::json("POST", "/api/session/ses_1/agent", 400, &body)]);
let client = Client::with_transport("http://test", Arc::new(memory)).unwrap();
let result = select(&client, "ses_1", Some("nope"), None).await;
assert_eq!(result, Err("Unknown agent: nope".to_owned()));
}
}
+1 -1
View File
@@ -1441,7 +1441,7 @@ pub async fn default_model(client: &Client, directory: &str) -> Option<(String,
/// `experimental.session.wait`: returns once the session is idle.
pub async fn wait(client: &Client, session: &str) -> Result<(), String> {
let input = ExperimentalSessionWaitInput { session_id: SessionID(session.to_owned()) };
client.experimental_session_wait(&input).await.map_err(|error| error.to_string())
client.experimental_session_wait(&input).await.map_err(|error| error.tui_message())
}
/// `session.interrupt`, for mini's two-press gesture (`resume: true`) and run's shutdown.