{"record":{"id":"221f730173c03053","repo":"vxcontrol/pentagi","slug":"failed-to-create-request-w-221f73","errorCode":null,"errorMessage":"failed to create request: %w","messagePattern":"failed to create request: %w","errorType":"exception","errorClass":"Fatal","httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/searchers/sploitus.go","lineNumber":132,"sourceCode":"\t\tTitle:  false, // search only for titles\n\t\tOffset: 0,\n\t}\n\n\tbodyBytes, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn \"\", Fatal(fmt.Errorf(\"failed to marshal request body: %w\", err))\n\t}\n\n\tclient, err := system.GetHTTPClient(s.cfg)\n\tif err != nil {\n\t\treturn \"\", Fatal(fmt.Errorf(\"failed to create http client: %w\", err))\n\t}\n\n\tclient.Timeout = sploitusRequestTimeout\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, sploitusAPIURL, bytes.NewReader(bodyBytes))\n\tif err != nil {\n\t\treturn \"\", Fatal(fmt.Errorf(\"failed to create request: %w\", err))\n\t}\n\n\t// Build referer with query to mimic browser behavior\n\treferer := fmt.Sprintf(\"https://sploitus.com/?query=%s\", url.QueryEscape(query))\n\n\t// Mimic Chrome browser headers to bypass Cloudflare protection\n\treq.Header.Set(\"Accept\", \"application/json\")\n\treq.Header.Set(\"Accept-Language\", \"en-US,en;q=0.9\")\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Origin\", \"https://sploitus.com\")\n\treq.Header.Set(\"Referer\", referer)\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36\")\n\treq.Header.Set(\"sec-ch-ua\", `\"Not:A-Brand\";v=\"99\", \"Google Chrome\";v=\"145\", \"Chromium\";v=\"145\"`)\n\treq.Header.Set(\"sec-ch-ua-mobile\", \"?0\")\n\treq.Header.Set(\"sec-ch-ua-platform\", `\"macOS\"`)\n\treq.Header.Set(\"sec-fetch-dest\", \"empty\")\n\treq.Header.Set(\"sec-fetch-mode\", \"cors\")\n\treq.Header.Set(\"sec-fetch-site\", \"same-origin\")","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/searchers/sploitus.go#L114-L150","documentation":"http.NewRequestWithContext fails to parse the method/URL/body for the POST to sploitusAPIURL; the searcher converts it to a Fatal error. Since sploitusAPIURL is a package constant, this fires only if the constant is a malformed URL or the marshaled body reader is nil/invalid.","triggerScenarios":"Handle() calls http.NewRequestWithContext(ctx, http.MethodPost, sploitusAPIURL, bytes.NewReader(bodyBytes)); error occurs when sploitusAPIURL fails url.Parse (bad scheme, control characters) — essentially only after an edit to the constant.","commonSituations":"A developer fat-fingers the sploitusAPIURL constant (e.g. typo like \"htp://\" or trailing spaces), or refactors to build the URL dynamically from config with an unparsable value.","solutions":["Read the wrapped error (it names the parse failure) and correct the sploitusAPIURL constant","Verify the URL parses: scheme must be http/https, no whitespace or control chars","If the URL is configurable, validate it at startup instead of inside the request path"],"exampleFix":"// before\nconst sploitusAPIURL = \"htp://sploitus.com/search\"\n// after\nconst sploitusAPIURL = \"https://sploitus.com/search\"","handlingStrategy":"validation","validationCode":"if u, err := url.Parse(sploitusAPIURL); err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") {\n    log.Fatalf(\"invalid sploitus API url: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"req, err := http.NewRequestWithContext(ctx, http.MethodPost, sploitusAPIURL, bytes.NewReader(bodyBytes))\nif err != nil {\n    return \"\", Fatal(fmt.Errorf(\"failed to create request: %w\", err))\n}","preventionTips":["Parse all hardcoded API URLs in package init/tests","Use httptest or a compile-time constant check for endpoint URLs","Never build URLs by string concatenation with unvalidated input"],"tags":["http-request","url-parsing","go"],"backgroundTag":"invalid-url-format","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}