fish2018/pansou · error

[ ] read response failed on page

Error message

[%s] read response failed on page %d: %w

What it means

searchImpl fetches Discourse search pages and reads each response body with io.ReadAll. If reading the body fails on the first page (no results yet), it returns this error wrapping the underlying read error with the page number; otherwise it logs a warning and stops.

Solutions

  1. Retry the search; transient network resets are the usual cause
  2. Check network stability/proxy configuration
  3. Increase the request timeout if large pages are being truncated
  4. If partial results are acceptable, rely on the warning path that keeps already-fetched results
Defensive patterns

Strategy: retry

Try / catch

links, err := plugin.Search(query)
if err != nil && strings.Contains(err.Error(), "read response failed") {
    time.Sleep(2 * time.Second)
    links, err = plugin.Search(query) // transient read failures usually succeed on retry
}

Prevention

When it happens

Trigger: io.ReadAll(resp.Body) returns an error during pagination of Discourse search results, with allResults empty.

Common situations: Connection reset or timeout mid-response, server closing the connection early (truncated chunked response), or network flakiness on mobile/unstable links.

Related errors


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

Appendix: source

Thrown at plugin/discourse/discourse.go:243

		if resp.StatusCode != 200 {
			resp.Body.Close()
			// 如果已经获取到一些结果,返回已有结果
			if len(allResults) > 0 {
				fmt.Printf("[%s] Warning: unexpected status code %d on page %d\n", p.Name(), resp.StatusCode, currentPage)
				break
			}
			return nil, fmt.Errorf("[%s] unexpected status code: %d on page %d", p.Name(), resp.StatusCode, currentPage)
		}

		// 读取响应体
		body, err := io.ReadAll(resp.Body)
		resp.Body.Close()
		if err != nil {
			if len(allResults) > 0 {
				fmt.Printf("[%s] Warning: failed to read page %d: %v\n", p.Name(), currentPage, err)
				break
			}
			return nil, fmt.Errorf("[%s] read response failed on page %d: %w", p.Name(), currentPage, err)
		}

		// 解析JSON响应
		var searchResp SearchResponse
		if err := json.Unmarshal(body, &searchResp); err != nil {
			if len(allResults) > 0 {
				fmt.Printf("[%s] Warning: failed to parse page %d: %v\n", p.Name(), currentPage, err)
				break
			}
			return nil, fmt.Errorf("[%s] parse json failed on page %d: %w", p.Name(), currentPage, err)
		}

		// 如果没有帖子了,停止获取
		if len(searchResp.Posts) == 0 {
			break
		}
		
		// 转换为SearchResult并去重

View on GitHub (pinned to beaa561337)