{"record":{"id":"64746eaee583f734","repo":"Tencent/WeKnora","slug":"failed-to-create-request-w-64746e","errorCode":null,"errorMessage":"failed to create request: %w","messagePattern":"failed to create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/bing.go","lineNumber":194,"sourceCode":"\t\t\tItems []struct {\n\t\t\t\tAnswerType string `json:\"answerType\"`\n\t\t\t\tValue      struct {\n\t\t\t\t\tID string `json:\"id\"`\n\t\t\t\t} `json:\"value\"`\n\t\t\t} `json:\"items\"`\n\t\t} `json:\"sidebar\"`\n\t} `json:\"rankingResponse\"`\n}\n\nfunc (p *BingProvider) buildParams(ctx context.Context, query string, maxResults int, includeDate bool) (*http.Request, error) {\n\tparams := url.Values{}\n\tparams.Set(\"q\", query)\n\tparams.Set(\"count\", strconv.Itoa(maxResults))\n\n\tqueryURL := fmt.Sprintf(\"%s?%s\", p.baseURL, params.Encode())\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", queryURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\treq.Header.Set(\"User-Agent\", defaultUserAgentHeader)\n\treq.Header.Set(\"Ocp-Apim-Subscription-Key\", p.apiKey)\n\treturn req, nil\n}\n","sourceCodeStart":176,"sourceCodeEnd":200,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/bing.go#L176-L200","documentation":"http.NewRequestWithContext failed while building the Bing GET request in buildParams, and the error is wrapped with this message. Given the URL is already encoded at this point, failure almost always means the resulting URL failed http-request parsing.","triggerScenarios":"baseURL is empty, malformed, or contains characters that make the assembled queryURL unparseable (e.g. spaces, invalid scheme) during a Search call.","commonSituations":"Misconfigured config file where the Bing endpoint is blank or contains whitespace; env var not expanded, leaving something like \"${BING_URL}\" or \"http:// example.com\" as baseURL.","solutions":["Inspect the wrapped error text; it names the offending URL component.","Verify the configured Bing endpoint is a full, valid absolute URL (e.g. https://api.bing.microsoft.com/v7.0/search).","Trim whitespace/quotes when loading the baseURL from env or config.","Pass a live, non-canceled context to Search (a canceled ctx can make the request construction fail)."],"exampleFix":"// before\nbaseURL: os.Getenv(\"BING_SEARCH_URL\")\n// after\nbaseURL := strings.TrimSpace(os.Getenv(\"BING_SEARCH_URL\"))\nif u, err := url.Parse(baseURL); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return errors.New(\"BING_SEARCH_URL must be an absolute https URL\")\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(cfg.BingBaseURL)\nif err != nil || u.Scheme != \"https\" || u.Host == \"\" {\n    return errors.New(\"bing baseURL must be an absolute https URL\")\n}","typeGuard":"func isValidURL(s string) bool {\n    u, err := url.Parse(s)\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"results, err := provider.Search(ctx, query, 10, false)\nif err != nil && strings.Contains(err.Error(), \"failed to create request\") {\n    // configuration bug, not transient — surface as startup/config error\n    return fmt.Errorf(\"bing provider misconfigured: %w\", err)\n}","preventionTips":["Validate all provider endpoint URLs at config-load time, not at request time.","Trim whitespace and quotes when reading URLs from env/config files.","Add a startup smoke test that builds a request against the configured endpoint."],"tags":["http","url","configuration","web-search","go"],"backgroundTag":"invalid-request-url","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}