fish2018/pansou · error

[quarkres] create request failed

Error message

[quarkres] create request failed: %w

What it means

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.

Solutions

  1. Strip control characters/newlines from the keyword before building the URL.
  2. Confirm apiBase has a valid scheme and no whitespace.
  3. Log searchURL on failure and run url.Parse on it to see the exact problem.
  4. Check the wrapped %w error for the precise parse failure.

Example fix

// before
searchURL := apiBase + url.QueryEscape(keyword)
req, err := http.NewRequest("GET", searchURL, nil)
// after
keyword = strings.TrimSpace(strings.Map(func(r rune) rune {
    if r < 32 || r == 127 { return -1 }
    return r
}, keyword))
searchURL := apiBase + url.QueryEscape(keyword)
req, err := http.NewRequest("GET", searchURL, nil)
if err != nil {
    return nil, fmt.Errorf("[quarkres] create request failed: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(searchURL)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
    return fmt.Errorf("cannot build search request for %q", searchURL)
}

Try / catch

results, err := p.doSearch(client, keyword, ext)
if err != nil {
    if strings.Contains(err.Error(), "create request failed") {
        // sanitize keyword / fix apiBase, then retry
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07). Data as JSON: /api/errors/c591505c1200f622. Report an issue: GitHub.

Appendix: source

Thrown at plugin/quarkres/quarkres.go:85

	Datetime time.Time `json:"datetime"`
	Links    []apiLink `json:"links"`
}

// apiResp 接口响应
type apiResp struct {
	Code    int       `json:"code"`
	Message string    `json:"message"`
	Total   int       `json:"total"`
	Data    []apiItem `json:"data"`
}

// doSearch 实际的搜索实现
func (p *QuarkResPlugin) doSearch(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {
	searchURL := apiBase + url.QueryEscape(keyword)

	req, err := http.NewRequest("GET", searchURL, nil)
	if err != nil {
		return nil, fmt.Errorf("[quarkres] create request failed: %w", err)
	}
	req.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")
	req.Header.Set("Accept", "application/json, text/plain, */*")
	req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
	req.Header.Set("Connection", "keep-alive")
	req.Header.Set("Referer", "https://squark.cc.cd/")

	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("[quarkres] request failed: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("[quarkres] HTTP %d", resp.StatusCode)
	}

	bodyBytes, err := io.ReadAll(resp.Body)

View on GitHub (pinned to beaa561337)