Tencent/WeKnora · error

failed to create request: %w

Error message

failed to create request: %w

What it means

HTTP client error in OllamaProvider.buildRequest: http.NewRequestWithContext failed to construct the POST to the provider's baseURL after the JSON body was marshaled. The %w retains the net/http cause; surfaced via Search as request-construction failure before any network I/O.

Source

Thrown at internal/infrastructure/web_search/ollama.go:101

	}
	logger.Infof(ctx, "[WebSearch][Ollama] returned %d results", len(results))
	return results, nil
}

func (p *OllamaProvider) buildRequest(ctx context.Context, query string, maxResults int) (*http.Request, error) {
	requestBody := map[string]interface{}{
		"query":       query,
		"max_results": maxResults,
	}

	bodyBytes, err := json.Marshal(requestBody)
	if err != nil {
		return nil, fmt.Errorf("failed to marshal request body: %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("Authorization", "Bearer "+p.apiKey)
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("User-Agent", defaultUserAgentHeader)

	return req, nil
}

func (p *OllamaProvider) doSearch(ctx context.Context, req *http.Request) ([]*types.WebSearchResult, error) {
	resp, err := p.client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify the Ollama baseURL constant/config is a valid absolute URL
  2. Check for a context cancelled before Search was called
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/infrastructure/web_search/ollama.go:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/5977c79b6802edb8. Report an issue: GitHub.