mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
handle errors correctly in the other tools
This commit is contained in:
@@ -86,6 +86,7 @@ func (t *fetchTool) Info() ToolInfo {
|
||||
"format": map[string]any{
|
||||
"type": "string",
|
||||
"description": "The format to return the content in (text, markdown, or html)",
|
||||
"enum": []string{"text", "markdown", "html"},
|
||||
},
|
||||
"timeout": map[string]any{
|
||||
"type": "number",
|
||||
@@ -126,7 +127,7 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
|
||||
)
|
||||
|
||||
if !p {
|
||||
return NewTextErrorResponse("Permission denied to fetch from URL: " + params.URL), nil
|
||||
return ToolResponse{}, permission.ErrorPermissionDenied
|
||||
}
|
||||
|
||||
client := t.client
|
||||
@@ -142,14 +143,14 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", params.URL, nil)
|
||||
if err != nil {
|
||||
return NewTextErrorResponse("Failed to create request: " + err.Error()), nil
|
||||
return ToolResponse{}, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "termai/1.0")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return NewTextErrorResponse("Failed to execute request: " + err.Error()), nil
|
||||
return ToolResponse{}, fmt.Errorf("failed to fetch URL: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user