fish2018/pansou · error

创建cookie jar失败

Error message

创建cookie jar失败: %w

What it means

createSessionClient wraps a failure from cookiejar.New, which initializes the cookie jar used to keep the same session across all search steps. The library returns this when a cookie jar cannot be constructed for the session client.

Solutions

  1. Retry the operation — the condition is transient/environmental if seen at all
  2. Inspect the wrapped cause from %w
  3. If custom Options were added to cookiejar.New, verify they are valid (especially PublicSuffixList)
  4. Report a bug with environment details if reproducible
Defensive patterns

Strategy: try-catch

Try / catch

results, err := plugin.Search(ctx, keyword)
if err != nil && strings.Contains(err.Error(), "创建cookie jar失败") {
    // environmental failure: log env details and retry once
    return retryOnce(err)
}

Prevention

When it happens

Trigger: cookiejar.New(nil) returns a non-nil error inside createSessionClient, invoked by searchImpl before any HTTP traffic. With nil Options this effectively never fails on mainstream platforms.

Common situations: Practically only seen on unusual runtimes (restricted sandboxes, exotic OS/arch builds) or if code was modified to pass invalid jar Options (e.g., invalid PublicSuffixList).

Related errors


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

Appendix: source

Thrown at plugin/qupanshe/qupanshe.go:123

	if DebugLog {
		fmt.Printf("[qupanshe] 获取搜索结果成功: 结果数=%d\n", len(results))
	}

	// Step 4: 关键词过滤
	filteredResults := plugin.FilterResultsByKeyword(results, keyword)
	if DebugLog {
		fmt.Printf("[qupanshe] 关键词过滤后: 过滤前=%d, 过滤后=%d\n", len(results), len(filteredResults))
	}

	return filteredResults, nil
}

// createSessionClient 创建带有Cookie管理的HTTP客户端
func (p *QupanshePlugin) createSessionClient(baseClient *http.Client) (*http.Client, error) {
	// 创建Cookie Jar来管理cookies
	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, fmt.Errorf("创建cookie jar失败: %w", err)
	}

	// 创建新的客户端,复制基础客户端的配置但添加Cookie管理
	sessionClient := &http.Client{
		Timeout:   baseClient.Timeout,
		Transport: baseClient.Transport,
		Jar:       jar, // ⭐ 关键:添加Cookie管理
	}

	if DebugLog {
		fmt.Printf("[qupanshe] 创建带Cookie管理的session客户端,超时时间: %v\n", sessionClient.Timeout)
	}

	return sessionClient, nil
}

// getFormhash 从首页获取真实的formhash值
func (p *QupanshePlugin) getFormhash(client *http.Client) (string, error) {

View on GitHub (pinned to beaa561337)