fish2018/pansou · error
[ ] 编码搜索关键词失败
Error message
[%s] 编码搜索关键词失败: %w
What it means
This error is thrown by DygangPlugin.fetchSearch when encodeGB18030 fails to convert the search keyword into GB18030 encoding. The dygang site expects search form fields encoded in GB18030 (Chinese encoding) rather than UTF-8, so keyword conversion is mandatory before building the POST form. The underlying encoder error is wrapped with the plugin name.
Solutions
- Sanitize the keyword: strip or transliterate characters not representable in GB18030 before searching
- Retry with a simplified keyword (keep only common CJK and ASCII characters)
- Check that the keyword input source is valid UTF-8 (validate/normalize with golang.org/x/text/encoding/unicode first)
- If the site now accepts UTF-8, switch to encoding GB18030 only when needed
Example fix
// before
encoded, err := encodeGB18030(keyword)
if err != nil {
return nil, fmt.Errorf("[%s] 编码搜索关键词失败: %w", p.Name(), err)
}
// after
cleaned := sanitizeForGB18030(keyword) // drop chars outside GB18030 repertoire
encoded, err := encodeGB18030(cleaned)
if err != nil {
return nil, fmt.Errorf("[%s] 编码搜索关键词失败: %w", p.Name(), err)
} Defensive patterns
Strategy: validation
Validate before calling
if !utf8.ValidString(keyword) { keyword = strings.ToValidUTF8(keyword, "") }
for _, r := range keyword {
if !isGB18030Encodable(r) { return fmt.Errorf("non-GB18030 character: %q", r) }
} Try / catch
results, err := dygang.Search(keyword)
if err != nil {
if strings.Contains(err.Error(), "编码搜索关键词失败") {
return dygang.Search(sanitizeForGB18030(keyword))
}
return err
} Prevention
- Normalize keyword encodings at ingestion time
- Keep a fallback path that retries with a cleaned keyword
- Log the offending rune on encoding failure for quick diagnosis
- Prefer plugins that accept UTF-8 when keyword sanitization is too lossy
When it happens
Trigger: Calling Search on the dygang plugin with a keyword whose text cannot be encoded to GB18030 (characters outside the GB18030 repertoire, or a malformed input encoding).
Common situations: Searching for titles containing rare Unicode symbols/emoji not representable in GB18030; input keyword arriving in a corrupt/mislabeled encoding; clipboard pasted text with invalid byte sequences.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/7abc9ef31929f1ae.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/dygang/dygang.go:168
}},
}
if imageURL != "" {
result.Images = []string{imageURL}
}
mu.Lock()
results = append(results, result)
mu.Unlock()
}
}()
}
wg.Wait()
return plugin.FilterResultsByKeyword(results, keyword), nil
}
func (p *Plugin) fetchSearch(client *http.Client, keyword string) (*goquery.Document, error) {
encoded, err := encodeGB18030(keyword)
if err != nil {
return nil, fmt.Errorf("[%s] 编码搜索关键词失败: %w", p.Name(), err)
}
form := "tempid=1&tbname=article&keyboard=" + url.QueryEscape(string(encoded)) + "&show=title%2Csmalltext&Submit="
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+searchPath, strings.NewReader(form))
if err != nil {
return nil, fmt.Errorf("[%s] 创建搜索请求失败: %w", p.Name(), err)
}
setHeaders(req, baseURL+"/")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("[%s] 搜索请求失败: %w", p.Name(), err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("[%s] 搜索请求返回 HTTP %d", p.Name(), resp.StatusCode)
}View on GitHub (pinned to beaa561337)