fish2018/pansou · warning
磁力链接为空
Error message
磁力链接为空
What it means
The magnet input element exists but its "value" attribute is missing or an empty string, so fetchMagnetLink throws this error. The page structure is right but the plugin got no usable magnet payload — typically the server rendered the form without filling in the value for this resource.
Solutions
- Inspect the actual page HTML for the resource; locate where the magnet string now lives (data attribute, hidden input, JS variable).
- Log which detailURL produced the empty magnet so pattern issues (specific resources) can be separated from template changes.
- Add a fallback selector set (e.g. input[name=hash], a[data-magnet]) before failing.
- Skip and continue enrichment for other results instead of treating one empty magnet as fatal (enrichWithMagnetLinks is per-result).
Example fix
// before
magnetLink, exists := magnetInput.Attr("value")
if !exists || magnetLink == "" {
return "", fmt.Errorf("磁力链接为空")
}
// after
magnetLink, exists := magnetInput.Attr("value")
if !exists || magnetLink == "" {
magnetLink, exists = magnetInput.Attr("data-magnet")
}
if !exists || magnetLink == "" {
return "", fmt.Errorf("磁力链接为空 (%s)", detailURL)
} Defensive patterns
Strategy: fallback
Validate before calling
v, ok := magnetInput.Attr("value")
if !ok || v == "" {
// try alternates before failing
v, ok = magnetInput.Attr("data-magnet")
} Try / catch
magnet, err := p.fetchMagnetLink(client, detailURL)
if err != nil && strings.Contains(err.Error(), "磁力链接为空") {
return "" // resource simply has no magnet; not fatal
} Prevention
- Check alternate attributes/elements holding the magnet value
- Log the affected detailURL to separate per-resource gaps from template changes
- Treat empty magnets as per-result degradation, not global failure
When it happens
Trigger: doc.Find("input#input-magnet") matched an element, but magnetInput.Attr("value") returns exists=false or magnetLink=="": the input is a placeholder/search box rather than the populated magnet field, or the resource genuinely has no magnet yet and the template renders an empty value.
Common situations: Site template change moving the actual magnet to a different attribute or element while leaving a decoy input with the same id; resources whose magnet is generated asynchronously and left empty in initial HTML; scraping a page variant (mobile/AMP) with an unfilled input.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/9131720297ccad65.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/wuji/wuji.go:346
if err != nil {
return "", fmt.Errorf("读取详情页响应失败: %w", err)
}
// 解析HTML
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(body)))
if err != nil {
return "", fmt.Errorf("详情页HTML解析失败: %w", err)
}
// 提取磁力链接
magnetInput := doc.Find("input#input-magnet")
if magnetInput.Length() == 0 {
return "", fmt.Errorf("未找到磁力链接输入框")
}
magnetLink, exists := magnetInput.Attr("value")
if !exists || magnetLink == "" {
return "", fmt.Errorf("磁力链接为空")
}
// 存入缓存
magnetCache.Store(detailURL, magnetCacheEntry{
MagnetLink: magnetLink,
Timestamp: time.Now(),
})
return magnetLink, nil
}
// cleanTitle 清理标题中的广告内容
func (p *WujiPlugin) cleanTitle(title string) string {
// 移除【】之间的广告内容
title = regexp.MustCompile(`【[^】]*】`).ReplaceAllString(title, "")
// 移除数字+【】格式的广告
title = regexp.MustCompile(`^\d+【[^】]*】`).ReplaceAllString(title, "")
// 移除[]之间的内容(如有需要)View on GitHub (pinned to beaa561337)