Tencent/WeKnora · error
failed to create request: %w
Error message
failed to create request: %w
What it means
http.NewRequestWithContext failed while constructing the GET request to the SearXNG /search endpoint. This means the request was never sent. In practice this fires when the composed URL (p.baseURL + "/search?" + encoded query) is malformed for Go's url.Parse, or the context is invalid.
Source
Thrown at internal/infrastructure/web_search/searxng.go:119
if maxResults <= 0 {
maxResults = 5
}
q := url.Values{}
q.Set("q", query)
q.Set("format", "json")
// Use "all" (SearXNG's documented value for "no language filter") instead
// of "auto", which is a UI-side default and not a valid /search parameter.
// safesearch is intentionally not set here so the value configured in the
// instance's settings.yml is honored.
q.Set("language", "all")
reqURL := p.baseURL + "/search?" + q.Encode()
logger.Infof(ctx, "[WebSearch][SearXNG] query=%q maxResults=%d url=%s", query, maxResults, p.baseURL)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "WeKnora/1.0")
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 {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
return nil, fmt.Errorf("searxng returned status %d: %s", resp.StatusCode, string(body))
}
var data searxngResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
p.lastUnresponsive = nilView on GitHub (pinned to 988cbb0330)
Solutions
- Log/inspect the wrapped error and the reqURL actually built; fix the baseURL in provider parameters
- url.Parse the baseURL yourself at construction time (ValidateSearxngBaseURL should catch most of these earlier)
- Trim whitespace and strip surrounding quotes from configured URLs
- Check the context passed to Search — ensure it is a live context.Background()-derived context
Example fix
// before baseURL := "https://searxng.example.com/ " // trailing space // after baseURL := strings.TrimSpace(strings.Trim(cfg.BaseURL, "\"'"))
Defensive patterns
Strategy: validation
Validate before calling
if _, err := url.Parse(baseURL); err != nil {
return fmt.Errorf("invalid searxng base_url: %w", err)
} Prevention
- Trim and de-quote configured URLs
- url.Parse the base URL at construction time
- Avoid template placeholders in config without expansion
When it happens
Trigger: baseURL containing characters invalid in a URL (spaces, control chars, unencoded braces) that survive url.Values encoding in the query but break the base; an already-canceled/invalid context is rare but also returns an error here.
Common situations: Tenant config holding an untrimmed or quoted base_url like "https://searxng.example.com/ " or "\"https://searxng.example.com\""; interpolation bugs leaving template placeholders in the URL.
Related errors
- failed to create request: %w
- failed to create Exa request: %w
- failed to create request: %w
- failed to execute request: %w
- searxng returned status %d: %s
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/a0a125bb8390a386.
Report an issue: GitHub.