handle errros correctly in the bash tool

Kujtim Hoxha created

Change summary

internal/llm/tools/bash.go        | 4 ++--
internal/permission/permission.go | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)

Detailed changes

internal/llm/tools/bash.go 🔗

@@ -273,14 +273,14 @@ func (b *bashTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
 			},
 		)
 		if !p {
-			return NewTextErrorResponse("permission denied"), nil
+			return ToolResponse{}, permission.ErrorPermissionDenied
 		}
 	}
 	startTime := time.Now()
 	shell := shell.GetPersistentShell(config.WorkingDirectory())
 	stdout, stderr, exitCode, interrupted, err := shell.Exec(ctx, params.Command, params.Timeout)
 	if err != nil {
-		return NewTextErrorResponse(fmt.Sprintf("error executing command: %s", err)), nil
+		return ToolResponse{}, fmt.Errorf("error executing command: %w", err)
 	}
 	took := time.Since(startTime).Milliseconds()
 

internal/permission/permission.go 🔗

@@ -1,6 +1,7 @@
 package permission
 
 import (
+	"errors"
 	"sync"
 	"time"
 
@@ -8,6 +9,8 @@ import (
 	"github.com/kujtimiihoxha/termai/internal/pubsub"
 )
 
+var ErrorPermissionDenied = errors.New("permission denied")
+
 type CreatePermissionRequest struct {
 	ToolName    string `json:"tool_name"`
 	Description string `json:"description"`
@@ -15,6 +18,7 @@ type CreatePermissionRequest struct {
 	Params      any    `json:"params"`
 	Path        string `json:"path"`
 }
+
 type PermissionRequest struct {
 	ID          string `json:"id"`
 	SessionID   string `json:"session_id"`