fish2018/pansou · error

read response failed

Error message

read response failed: %w

What it means

Wrapped I/O error in GetTopicDetail (plugin/discourse/discourse.go:489): the topic detail response arrived with HTTP 200 but its body could not be fully read (connection dropped mid-transfer, timeout). The JSON was never parsed, so the failure is transport-level.

Solutions

  1. Retry the detail request; the cause is usually transient
  2. Check network/proxy stability
  3. Increase the HTTP client timeout if large responses are truncated
Defensive patterns

Strategy: retry

Try / catch

links, err := plugin.GetTopicDetail(id)
if err != nil && strings.Contains(err.Error(), "read response failed") {
    time.Sleep(time.Second)
    links, err = plugin.GetTopicDetail(id)
}

Prevention

When it happens

Trigger: io.ReadAll(resp.Body) fails after a successful detail request — connection dropped mid-body, truncated chunked encoding, timeout during read.

Common situations: 服务端提前关闭连接;响应体过大超过读取时限。

Related errors


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

Appendix: source

Thrown at plugin/discourse/discourse.go:489

	// 构建详情URL
	detailURL := fmt.Sprintf(detailURLTemplate, topicID)

	// 发送详情请求
	resp, err := p.scraper.Get(detailURL)
	if err != nil {
		return nil, fmt.Errorf("detail request failed: %w", err)
	}
	defer resp.Body.Close()

	// 检查HTTP状态码
	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
	}

	// 读取响应体
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("read response failed: %w", err)
	}

	// 解析JSON响应
	var detailResp DetailResponse
	if err := json.Unmarshal(body, &detailResp); err != nil {
		return nil, fmt.Errorf("parse json failed: %w", err)
	}

	// 提取第一个帖子的链接
	if len(detailResp.PostStream.Posts) == 0 {
		return nil, fmt.Errorf("no posts found")
	}

	mainPost := detailResp.PostStream.Posts[0]
	
	// 从 link_counts 中提取网盘链接
	var links []model.Link
	for _, linkCount := range mainPost.LinkCounts {

View on GitHub (pinned to beaa561337)