{"record":{"id":"c591505c1200f622","repo":"fish2018/pansou","slug":"quarkres-create-request-failed-w","errorCode":null,"errorMessage":"[quarkres] create request failed: %w","messagePattern":"\\[quarkres\\] create request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/quarkres/quarkres.go","lineNumber":85,"sourceCode":"\tDatetime time.Time `json:\"datetime\"`\n\tLinks    []apiLink `json:\"links\"`\n}\n\n// apiResp 接口响应\ntype apiResp struct {\n\tCode    int       `json:\"code\"`\n\tMessage string    `json:\"message\"`\n\tTotal   int       `json:\"total\"`\n\tData    []apiItem `json:\"data\"`\n}\n\n// doSearch 实际的搜索实现\nfunc (p *QuarkResPlugin) doSearch(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {\n\tsearchURL := apiBase + url.QueryEscape(keyword)\n\n\treq, err := http.NewRequest(\"GET\", searchURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[quarkres] create request failed: %w\", err)\n\t}\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36\")\n\treq.Header.Set(\"Accept\", \"application/json, text/plain, */*\")\n\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9\")\n\treq.Header.Set(\"Connection\", \"keep-alive\")\n\treq.Header.Set(\"Referer\", \"https://squark.cc.cd/\")\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[quarkres] request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"[quarkres] HTTP %d\", resp.StatusCode)\n\t}\n\n\tbodyBytes, err := io.ReadAll(resp.Body)","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/quarkres/quarkres.go#L67-L103","documentation":"QuarkResPlugin.doSearch builds a GET request to apiBase+escaped keyword; if http.NewRequest fails it returns \"[quarkres] create request failed\" wrapping the cause. Given the URL is constructed from a constant base plus url.QueryEscape(keyword), failure indicates malformed URL text — usually control characters in the keyword or a broken apiBase constant.","triggerScenarios":"http.NewRequest errors because searchURL fails url.Parse — e.g. keyword containing raw newlines/control bytes that survive QueryEscape, or apiBase misconfigured without a valid scheme.","commonSituations":"User input passed through with embedded newlines (multi-line paste); apiBase edited with a typo (missing https://, stray spaces); plugin source modified with an invalid base URL.","solutions":["Strip control characters/newlines from the keyword before building the URL.","Confirm apiBase has a valid scheme and no whitespace.","Log searchURL on failure and run url.Parse on it to see the exact problem.","Check the wrapped %w error for the precise parse failure."],"exampleFix":"// before\nsearchURL := apiBase + url.QueryEscape(keyword)\nreq, err := http.NewRequest(\"GET\", searchURL, nil)\n// after\nkeyword = strings.TrimSpace(strings.Map(func(r rune) rune {\n    if r < 32 || r == 127 { return -1 }\n    return r\n}, keyword))\nsearchURL := apiBase + url.QueryEscape(keyword)\nreq, err := http.NewRequest(\"GET\", searchURL, nil)\nif err != nil {\n    return nil, fmt.Errorf(\"[quarkres] create request failed: %w\", err)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(searchURL)\nif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") {\n    return fmt.Errorf(\"cannot build search request for %q\", searchURL)\n}","typeGuard":null,"tryCatchPattern":"results, err := p.doSearch(client, keyword, ext)\nif err != nil {\n    if strings.Contains(err.Error(), \"create request failed\") {\n        // sanitize keyword / fix apiBase, then retry\n    }\n}","preventionTips":["Strip control characters and trim whitespace from keywords before escaping","Validate apiBase at plugin init (scheme + host present)","Use url.Values / url.URL building instead of string concatenation where possible"],"tags":["http","url","request-construction"],"backgroundTag":"invalid-url","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}