Skip to content

Commit 6a8812f

Browse files
authored
fix: outputs error when tool execution fails (#637)
* fix: outputs error when tool execution fails * fix: fmts with cargo nightly * fix: makes aws tool to return error when exit code is not 0
1 parent 6a36c04 commit 6a8812f

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

crates/q_cli/src/cli/chat/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,25 +533,37 @@ Hi, I'm <g>Amazon Q</g>. I can answer questions about your workspace and tooling
533533
match tool.1.invoke(&self.ctx, self.output).await {
534534
Ok(result) => {
535535
debug!("tool result output: {:#?}", result);
536+
if let Some(builder) = corresponding_builder {
537+
builder.is_success = Some(true);
538+
}
539+
536540
tool_results.push(ToolResult {
537541
tool_use_id: tool.0,
538542
content: vec![result.into()],
539543
status: ToolResultStatus::Success,
540544
});
541-
if let Some(builder) = corresponding_builder {
542-
builder.is_success = Some(true);
543-
}
544545
},
545546
Err(err) => {
546547
error!(?err, "An error occurred processing the tool");
547548
tool_results.push(ToolResult {
548549
tool_use_id: tool.0,
549550
content: vec![ToolResultContentBlock::Text(format!(
550-
"An error occurred processing the tool: {}",
551+
"An error occurred processing the tool: \n{}",
551552
err
552553
))],
553554
status: ToolResultStatus::Error,
554555
});
556+
557+
execute!(
558+
self.output,
559+
style::SetAttribute(Attribute::Bold),
560+
style::Print("Tool execution failed: "),
561+
style::SetAttribute(Attribute::Reset),
562+
style::SetForegroundColor(Color::Red),
563+
style::Print(err),
564+
style::SetForegroundColor(Color::Reset)
565+
)?;
566+
555567
if let Some(builder) = corresponding_builder {
556568
builder.is_success = Some(false);
557569
}

crates/q_cli/src/cli/chat/tools/use_aws.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ impl UseAws {
8383
let stdout = output.stdout.to_str_lossy();
8484
let stderr = output.stderr.to_str_lossy();
8585

86-
Ok(InvokeOutput {
87-
output: OutputKind::Json(serde_json::json!({
88-
"exit_status": status,
89-
"stdout": stdout,
90-
"stderr": stderr
91-
})),
92-
})
86+
if status.eq("0") {
87+
Ok(InvokeOutput {
88+
output: OutputKind::Json(serde_json::json!({
89+
"exit_status": status,
90+
"stdout": stdout,
91+
"stderr": stderr
92+
})),
93+
})
94+
} else {
95+
Err(eyre::eyre!(stderr.to_string()))
96+
}
9397
}
9498

9599
pub fn show_readable_intention(&self, updates: &mut impl Write) -> Result<()> {

0 commit comments

Comments
 (0)