mirror of
https://github.com/sst/opencode.git
synced 2025-08-10 08:18:02 +00:00
handle errors correctly in the other tools
This commit is contained in:
parent
921f5ee5bd
commit
0b3e5f5bd4
8 changed files with 72 additions and 26 deletions
|
@ -27,6 +27,11 @@ type grepMatch struct {
|
|||
modTime time.Time
|
||||
}
|
||||
|
||||
type GrepMetadata struct {
|
||||
NumberOfMatches int `json:"number_of_matches"`
|
||||
Truncated bool `json:"truncated"`
|
||||
}
|
||||
|
||||
type grepTool struct{}
|
||||
|
||||
const (
|
||||
|
@ -110,7 +115,7 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
|
|||
|
||||
matches, truncated, err := searchFiles(params.Pattern, searchPath, params.Include, 100)
|
||||
if err != nil {
|
||||
return NewTextErrorResponse(fmt.Sprintf("error searching files: %s", err)), nil
|
||||
return ToolResponse{}, fmt.Errorf("error searching files: %w", err)
|
||||
}
|
||||
|
||||
var output string
|
||||
|
@ -127,7 +132,13 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
|
|||
}
|
||||
}
|
||||
|
||||
return NewTextResponse(output), nil
|
||||
return WithResponseMetadata(
|
||||
NewTextResponse(output),
|
||||
GrepMetadata{
|
||||
NumberOfMatches: len(matches),
|
||||
Truncated: truncated,
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func pluralize(count int) string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue