fish2018/pansou · error

[susu] 创建按钮详情请求失败

Error message

[susu] 创建按钮详情请求失败: %w

What it means

http.NewRequestWithContext rejected the susu button-detail POST target (ButtonDetailURL) or its body. Fires only on a malformed URL or unreadable reader — the site has not been contacted yet. Input at fault: the configured ButtonDetailURL constant.

Solutions

  1. Validate ButtonDetailURL at init
  2. This is a programming/config bug, not a runtime condition: fix the constant
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at plugin/susu/susu.go:448 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at plugin/susu/susu.go:448

	cacheKey := fmt.Sprintf("%s:%d:%d", postID, index, i)

	// 检查缓存
	if cachedLink, ok := buttonDetailCache.Load(cacheKey); ok {
		return cachedLink.(model.Link), nil
	}

	form := url.Values{
		"post_id": {postID},
		"index":   {fmt.Sprintf("%d", index)},
		"i":       {fmt.Sprintf("%d", i)},
		"guest":   {""},
	}
	ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
	defer cancel()

	req, err := http.NewRequestWithContext(ctx, http.MethodPost, ButtonDetailURL, strings.NewReader(form.Encode()))
	if err != nil {
		return model.Link{}, fmt.Errorf("[susu] 创建按钮详情请求失败: %w", err)
	}
	setAPIHeaders(req, fmt.Sprintf("%s/download?post_id=%s&index=%d&i=%d", BaseURL, postID, index, i))

	// 发送请求(带重试)
	resp, err := p.doRequestWithRetry(client, req, MaxRetries)
	if err != nil {
		return model.Link{}, fmt.Errorf("[susu] 获取按钮详情失败: %w", err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return model.Link{}, fmt.Errorf("[susu] 按钮详情请求返回状态码: %d", resp.StatusCode)
	}

	// 读取响应体
	respBody, err := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
	if err != nil {
		return model.Link{}, fmt.Errorf("[susu] 读取按钮详情失败: %w", err)
	}

View on GitHub (pinned to beaa561337)