fish2018/pansou · error

[ ] 创建session客户端失败

Error message

[%s] 创建session客户端失败: %w

What it means

searchImpl wraps any failure from createSessionClient, which builds a cookie-managed HTTP client for the qupanshe search flow. The only failure path inside createSessionClient is cookiejar.New, which fails if the underlying cookie jar implementation cannot be initialized. Wrapping with %w preserves the root cause for diagnosis.

Solutions

  1. Retry the search; the failure is transient/environmental in practice
  2. Check the wrapped root cause (err inside %w) for platform-specific jar initialization errors
  3. Upgrade/verify the Go runtime on the host
  4. If reproducible, file a bug with the wrapped error message
Defensive patterns

Strategy: try-catch

Try / catch

results, err := plugin.Search(ctx, keyword)
if err != nil {
    if strings.Contains(err.Error(), "创建session客户端失败") {
        // session client init failed; retry once or surface env problem
        return retryOrFallback(err)
    }
    return err
}

Prevention

When it happens

Trigger: cookiejar.New(nil) returns an error while createSessionClient initializes the session client at the start of searchImpl. In practice this is nearly impossible on standard Go runtimes since cookiejar.New with nil Options never fails.

Common situations: Runtime environments with constrained crypto/rand availability or exotic platform builds; otherwise this error indicates a truly unexpected internal failure rather than user misconfiguration.

Related errors


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

Appendix: source

Thrown at plugin/qupanshe/qupanshe.go:66

	}
	return result.Results, nil
}

// SearchWithResult 执行搜索并返回包含IsFinal标记的结果
func (p *QupanshePlugin) SearchWithResult(keyword string, ext map[string]interface{}) (model.PluginSearchResult, error) {
	return p.AsyncSearchWithResult(keyword, p.searchImpl, p.MainCacheKey, ext)
}

// searchImpl 实现搜索逻辑
func (p *QupanshePlugin) searchImpl(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {
	if DebugLog {
		fmt.Printf("[qupanshe] 开始搜索: keyword=%s\n", keyword)
	}

	// 创建带有Cookie管理的专用客户端,确保整个搜索过程使用同一个session
	sessionClient, err := p.createSessionClient(client)
	if err != nil {
		return nil, fmt.Errorf("[%s] 创建session客户端失败: %w", p.Name(), err)
	}

	if DebugLog {
		fmt.Printf("[qupanshe] 创建session客户端成功,开始三步搜索流程\n")
	}

	// Step 1: 获取首页formhash(使用session客户端)
	formhash, err := p.getFormhash(sessionClient)
	if err != nil {
		if DebugLog {
			fmt.Printf("[qupanshe] 获取formhash失败: %v\n", err)
		}
		return nil, fmt.Errorf("[%s] 获取formhash失败: %w", p.Name(), err)
	}
	if DebugLog {
		fmt.Printf("[qupanshe] 获取到formhash: %s\n", formhash)
	}

View on GitHub (pinned to beaa561337)