fish2018/pansou · error

未找到buildId

Error message

未找到buildId

What it means

getBuildId received a 200 response but extractBuildId could not find a buildId string in the HTML/JS body. It fails only when buildIdCache is empty; otherwise the previous cached buildId is returned via graceful degradation.

Solutions

  1. Inspect the response body and update extractBuildId's pattern to match the new markup.
  2. Clear the empty/stale cache state and retry after the upstream stabilizes.
  3. Check whether a bot-protection page was returned; add/refresh appropriate headers or cookies.
  4. Pin/report the upstream change; the cache will keep searches working only until it is cleared.

Example fix

// before
buildId := extractBuildId(body)
// after
buildId := extractBuildId(body)
if buildId == "" {
    log.Printf("buildId extraction failed, body head: %.200s", body)
}
Defensive patterns

Strategy: fallback

Try / catch

if err != nil && strings.Contains(err.Error(), "未找到buildId") {
    // upstream markup/behavior changed; treat as upstream outage and fall back
    return cachedOrEmptyResults, nil
}

Prevention

When it happens

Trigger: Upstream page loaded fine but its markup changed (the regex/extract pattern no longer matches), or the response was a challenge/placeholder page with no buildId, on a call where no cached buildId exists.

Common situations: Upstream site redeployed and changed how buildId is embedded (script tag moved/renamed), bot-protection interstitial page returned instead of the real page, or a CDN served an error page with 200 status.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at plugin/pansearch/pansearch.go:447

		// 如果读取响应失败,但有旧的缓存,使用旧的缓存(优雅降级)
		if buildIdCache != "" {
			// fmt.Printf("读取响应失败,使用旧的buildId: %v\n", err)
			return buildIdCache, nil
		}
		return "", fmt.Errorf("读取响应失败: %w", err)
	}
	body := bodyBuilder.String()

	// 使用提取函数获取 buildId
	buildId := extractBuildId(body)

	// 如果提取失败,但有旧的缓存,使用旧的缓存(优雅降级)
	if buildId == "" {
		if buildIdCache != "" {
			// fmt.Println("未找到buildId,使用旧的buildId")
			return buildIdCache, nil
		}
		return "", fmt.Errorf("未找到buildId")
	}

	// 更新缓存
	buildIdCache = buildId
	buildIdCacheTime = time.Now()

	return buildId, nil
}

// getBaseURL 获取完整的API基础URL
func (p *PanSearchAsyncPlugin) getBaseURL(client *http.Client) (string, error) {
	buildId, err := p.getBuildId(client)
	if err != nil {
		return "", err
	}

	return fmt.Sprintf(BaseURLTemplate, buildId), nil
}

View on GitHub (pinned to beaa561337)