Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell command fail exit codes are not tool failures #329

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions crates/goose/src/developer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,28 @@ impl DeveloperSystem {
.map_err(|e| AgentError::ExecutionError(e.to_string()))?;

let output_str = String::from_utf8_lossy(&output.stdout).to_string();
if !output.status.success() {
return Err(AgentError::ExecutionError(output_str));
}

let formatted = formatdoc! {"
## Output
let formatted = if !output.status.success() {
formatdoc! {"
## Command Errored with exit code: {}

```
{}
```
",
output.status.code().unwrap_or(1),
output_str
}
} else {
formatdoc! {"
## Output

```
{}
```
",
output_str
```
{}
```
",
output_str
}
};

Ok(vec![Content::text(formatted)])
Expand Down Expand Up @@ -600,6 +610,18 @@ mod tests {
.contains(&std::env::current_dir().unwrap().display().to_string()));
}

#[tokio::test]
async fn test_bash_failed_command_result_is_not_tool_error() {
let system = get_system().await;

let tool_call = ToolCall::new("bash", json!({ "working_dir": ".", "command": "false" }));
let result = system.call(tool_call).await.unwrap();
assert!(result[0]
.as_text()
.unwrap()
.starts_with("## Command Errored with exit code"));
}

#[tokio::test]
async fn test_bash_invalid_directory() {
let system = get_system().await;
Expand Down
Loading