fish2018/pansou · error

[ ] 生成搜索参数失败

Error message

[%s] 生成搜索参数失败: %w

What it means

encryptPayload failed while building the encrypted search request body from the searchPayload and the fetched apiConfig. The plugin cannot construct a valid request, so the search is aborted before any HTTP call is made and the underlying crypto/packing error is wrapped with this message.

Solutions

  1. Inspect the wrapped error from encryptPayload for the root cause (missing field, serialization, crypto)
  2. Re-fetch the config via fetchConfig and confirm URLVersion/UserID are populated and current
  3. Ensure the encryption implementation matches the server version tied to config.URLVersion
  4. Update searchPayload fields to match the expected API schema

Example fix

// before
cfg, _ := p.fetchConfig(ctx, client) // stale cached config
// after
cfg, err := p.fetchConfig(ctx, client)
if err != nil { return nil, err } // always search with a freshly validated config
Defensive patterns

Strategy: validation

Validate before calling

if config.URLVersion == "" || config.UserID == "" {
    return errors.New("cannot encrypt payload: config missing URLVersion/UserID")
}

Try / catch

items, err := p.search(ctx, client, cfg, kw)
if err != nil {
    if strings.Contains(err.Error(), "生成搜索参数失败") {
        log.Printf("payload encryption failed; re-fetching config: %v", err)
        cfg, err = p.fetchConfig(ctx, client)
        if err == nil {
            items, err = p.search(ctx, client, cfg, kw)
        }
    }
    return err
}

Prevention

When it happens

Trigger: encryptPayload(payload, config) returns an error inside search, e.g. because config fields (URLVersion/UserID/Start/End) are unsuitable for key derivation or the payload cannot be serialized/encrypted.

Common situations: A config field is empty or malformed despite validation (schema drift), the encryption scheme/keys no longer match the server version indicated by URLVersion, or the payload struct changed and breaks serialization.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at plugin/yingso/yingso.go:221

	}
	if config.URLVersion == "" || config.UserID == "" || config.Start < 0 || config.End <= config.Start || config.End > 24 {
		return apiConfig{}, fmt.Errorf("[%s] 接口配置缺少必要字段", p.Name())
	}
	return config, nil
}

func (p *YingsoPlugin) search(ctx context.Context, client *http.Client, config apiConfig, keyword string) ([]searchItem, error) {
	payload := searchPayload{
		PageSize: pageSize,
		PageNum:  1,
		Title:    keyword,
		Root:     0,
		Category: "all",
		UserID:   config.UserID,
	}
	encrypted, err := encryptPayload(payload, config)
	if err != nil {
		return nil, fmt.Errorf("[%s] 生成搜索参数失败: %w", p.Name(), err)
	}

	var response apiEnvelope[[]searchItem]
	endpoint := fmt.Sprintf("%s/%s/search", p.apiBaseURL, url.PathEscape(config.URLVersion))
	if err := p.requestJSON(ctx, client, http.MethodPost, endpoint, encrypted, &response); err != nil {
		return nil, fmt.Errorf("[%s] 搜索请求失败: %w", p.Name(), err)
	}
	if response.Code != http.StatusOK {
		return nil, fmt.Errorf("[%s] 搜索接口异常: code=%d msg=%s", p.Name(), response.Code, response.Msg)
	}
	return response.Data, nil
}

func (p *YingsoPlugin) resolveItem(ctx context.Context, client *http.Client, config apiConfig, item searchItem) (model.SearchResult, error) {
	payload := getKeyPayload{ID: item.ID, UserID: config.UserID}
	encrypted, err := encryptPayload(payload, config)
	if err != nil {
		return model.SearchResult{}, err

View on GitHub (pinned to beaa561337)