(665719e) Report an ambiguous search as an error, not a print and exit

resolve_ticket printed the candidate list to stdout and called
process::exit(1) from inside a helper. That combination is the one thing
the opencode wrapper cannot relay: it throws on the non-zero exit and
keeps stderr, so the list was thrown away and the agent saw a bare exit
code with nothing to choose from.

Return an error carrying the rendered list instead. It reaches stderr the
way every other error does, the exit code stays non-zero so `show x && ...`
still fails, and no process::exit remains in util.rs.

The wrapper half, which was dropping stderr on the floor regardless,
follows in 3e8b6fa.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-20 14:10:02 +02:00
co-authored by Claude Opus 5
parent c675da1d2a
commit a434f82928
2 changed files with 88 additions and 26 deletions
+25 -12
View File
@@ -95,6 +95,30 @@ pub fn get_git_user() -> Option<String> {
}
})
}
/// The candidate list for an ambiguous search, as an error rather than a print
/// followed by `exit(1)`.
///
/// An error reaches the user on stderr and leaves the exit code non-zero, which
/// is the only combination the opencode wrapper can relay: it throws on the exit
/// code and keeps stderr, so the list printed to stdout was thrown away and the
/// agent saw nothing but a bare exit code.
fn ambiguous(search: &str, matches: &[(String, String, String, String)]) -> anyhow::Error {
let mut message = format!("Multiple tickets found matching '{}':\n", search);
for (i, (status, title, _, id)) in matches.iter().enumerate() {
message.push_str(&format!(
" {}. ({}) {} [{}]\n",
i + 1,
color_text(short_id(id), "red"),
title,
color_text(status, "orange"),
));
}
message.push_str("\nUse the displayed ID or a more specific search term to select.");
anyhow!(message)
}
pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, String, String)> {
let statuses = status_dirs();
let mut matches: Vec<(String, String, String, String)> = Vec::new();
@@ -146,18 +170,7 @@ pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, Stri
}
if matches.len() > 1 {
println!("Multiple tickets found matching '{}':", search);
for (i, (status, title, _, id)) in matches.iter().enumerate() {
println!(
" {}. ({}) {} [{}]",
i + 1,
color_text(short_id(id), "red"),
title,
color_text(status, "orange"),
);
}
println!("\nUse the displayed ID or a more specific search term to select.");
std::process::exit(1);
return Err(ambiguous(search, &matches));
}
let (status, title, content, _short_id) = matches.remove(0);