Tencent/WeKnora · error
failed to execute request: %w
Error message
failed to execute request: %w
What it means
Tavily web search provider wraps any network-layer failure from the HTTP client (p.client.Do) with this error. It means the HTTP request to the Tavily API could not be executed at all — connection setup, DNS, TLS, or transport failure — not an HTTP error status. The original error is preserved via %w for errors.Is/As inspection.
Source
Thrown at internal/infrastructure/web_search/tavily.go:86
APIKey: p.apiKey,
Query: query,
MaxResults: maxResults,
}
bodyBytes, err := json.Marshal(reqBody)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}
req, err := http.NewRequestWithContext(ctx, "POST", p.baseURL, bytes.NewReader(bodyBytes))
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := p.client.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to execute request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
respBody, _ := io.ReadAll(resp.Body)
logger.Warnf(ctx, "[WebSearch][Tavily] API returned status %d: %s", resp.StatusCode, string(respBody))
return nil, fmt.Errorf("tavily API returned status %d: %s", resp.StatusCode, string(respBody))
}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response: %w", err)
}
var respData tavilySearchResponse
if err := json.Unmarshal(respBody, &respData); err != nil {
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
}View on GitHub (pinned to 988cbb0330)
Solutions
- Check network connectivity and DNS resolution to api.tavily.com (curl -v https://api.tavily.com).
- Verify proxy/firewall settings allow outbound HTTPS (HTTPS_PROXY, HTTP_PROXY env vars).
- Inspect the wrapped error with errors.Is(err, context.DeadlineExceeded) / net.Error to identify timeouts vs connection failures.
- Increase client timeout or retry with backoff for transient network faults; ensure the context deadline is generous enough.
Example fix
// before
results, err := provider.Search(ctx, query, 5, false)
if err != nil { return err }
// after
results, err := provider.Search(ctx, query, 5, false)
if err != nil {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
return retryWithBackoff(ctx)
}
return fmt.Errorf("tavily search failed: %w", err)
} Defensive patterns
Strategy: retry
Validate before calling
// before calling
if err := ctx.Err(); err != nil { return fmt.Errorf("context already cancelled: %w", err) }
// optionally probe connectivity:
conn, err := net.DialTimeout("tcp", "api.tavily.com:443", 3*time.Second)
if err != nil { return fmt.Errorf("tavily unreachable: %w", err) }
conn.Close() Type guard
func isNetworkErr(err error) bool {
var netErr net.Error
if errors.As(err, &netErr) { return true }
var dnsErr *net.DNSError
return errors.As(err, &dnsErr)
} Try / catch
results, err := provider.Search(ctx, q, 5, false)
if err != nil {
if strings.Contains(err.Error(), "failed to execute request") {
// transient network problem: retry with backoff
results, err = retry(ctx, 3, func() error { _, err := provider.Search(ctx, q, 5, false); return err })
}
if err != nil { return err }
} Prevention
- Set a generous context deadline and honor cancellation
- Configure reasonable client timeouts and connection pooling
- Verify egress/proxy allowlists for api.tavily.com in your deployment
- Use errors.Is/errors.As on the wrapped error to classify before retrying
When it happens
Trigger: Calling provider.Search when the network to api.tavily.com is unreachable: DNS resolution failure, connection refused/timeout, TLS handshake error, or a cancelled/expired context before the response is received.
Common situations: No internet or firewall/proxy blocking outbound HTTPS, misconfigured HTTP proxy env vars, transient DNS outages in containers, request context cancelled by an upstream timeout, or an invalid custom p.client configuration.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- failed to perform request: %w
- failed to read response: %w
- duckduckgo HTML search failed: %w
- duckduckgo API search failed: %w
- failed to execute request: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/a2bedf5993f9364e.
Report an issue: GitHub.