claudetool/bash: include partial output in error message for timeouts
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: se1cb20e743a878d4k
diff --git a/claudetool/bash.go b/claudetool/bash.go
index adbd12c..827235a 100644
--- a/claudetool/bash.go
+++ b/claudetool/bash.go
@@ -138,12 +138,7 @@
// For foreground commands, use executeBash
out, execErr := executeBash(ctx, req)
- // If there's a timeout error, we still want to return the partial output
if execErr != nil {
- if out != "" && strings.Contains(execErr.Error(), "timed out") {
- // Return both the partial output and the error
- return llm.TextContent(out), execErr
- }
return nil, execErr
}
return llm.TextContent(out), nil
@@ -186,15 +181,6 @@
err := cmd.Wait()
close(done)
- if execCtx.Err() == context.DeadlineExceeded {
- // Get the partial output that was captured before the timeout
- partialOutput := output.String()
- // Truncate if the output is too large
- if len(partialOutput) > maxBashOutputLength {
- partialOutput = partialOutput[:maxBashOutputLength] + "\n[output truncated due to size]\n"
- }
- return partialOutput, fmt.Errorf("command timed out after %s - partial output included", req.timeout())
- }
longOutput := output.Len() > maxBashOutputLength
var outstr string
if longOutput {
@@ -206,6 +192,15 @@
outstr = output.String()
}
+ if execCtx.Err() == context.DeadlineExceeded {
+ // Get the partial output that was captured before the timeout
+ partialOutput := output.String()
+ // Truncate if the output is too large
+ if len(partialOutput) > maxBashOutputLength {
+ partialOutput = partialOutput[:maxBashOutputLength] + "\n[output truncated due to size]\n"
+ }
+ return "", fmt.Errorf("command timed out after %s\nCommand output (until it timed out):\n%s", req.timeout(), outstr)
+ }
if err != nil {
return "", fmt.Errorf("command failed: %w\n%s", err, outstr)
}