Tencent/WeKnora · error
failed to unmarshal response: %w
Error message
failed to unmarshal response: %w
What it means
Deserialization error in BaiduProvider.doSearch: the 200 response body (already limited to 2MB) could not be unmarshaled into baiduSearchResponse. The %w wraps the JSON error, indicating Baidu returned a schema the provider cannot interpret; raised after the non-200 status branch, so it specifically means 'unparseable success response'.
Source
Thrown at internal/infrastructure/web_search/baidu.go:140
resp, err := p.client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(io.LimitReader(resp.Body, 2<<20)) // 2MB limit
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
logger.Warnf(ctx, "[WebSearch][Baidu] API returned status %d: %s", resp.StatusCode, string(body))
return nil, fmt.Errorf("baidu API returned status %d: %s", resp.StatusCode, string(body))
}
var respData baiduSearchResponse
if err := json.Unmarshal(body, &respData); err != nil {
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
}
// Check for API-level error (returned with 200 status)
if respData.Code != 0 {
return nil, fmt.Errorf("baidu API error (code %d): %s", respData.Code, respData.Message)
}
results := make([]*types.WebSearchResult, 0, len(respData.References))
for _, ref := range respData.References {
result := &types.WebSearchResult{
Title: ref.Title,
URL: ref.URL,
Content: ref.Content,
Source: "baidu",
}
if includeDate && ref.Date != "" {
if t, err := parseBaiduDate(ref.Date); err == nil {View on GitHub (pinned to 988cbb0330)
Solutions
- Log the raw body to see what was actually returned
- Check for Baidu API schema changes and update the response structs
- Retry once; a truncated body can be transient
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/infrastructure/web_search/baidu.go:140 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/a1516af895df8979.
Report an issue: GitHub.