fish2018/pansou · error

请求失败

Error message

请求失败: %w

What it means

getBuildId performed the HTTP request but it failed (respErr != nil or resp == nil) — e.g. DNS failure, timeout, connection refused — and there is no cached buildId to fall back on. The underlying error is wrapped in this error.

Solutions

  1. Check network connectivity and whether the target site is reachable (curl the base URL)
  2. Increase the HTTP client timeout and let the existing retry loop run
  3. Persist buildIdCache to disk so restarts keep a fallback value
  4. Configure a proxy if the site is blocked from your network

Example fix

// before
buildId, err := getBuildId(ctx)
if err != nil { return "", err }
// after
buildId, err := getBuildId(ctx)
if err != nil {
    if cached := loadBuildIdFromDisk(); cached != "" {
        return cached, nil
    }
    return "", err
}
Defensive patterns

Strategy: retry

Validate before calling

resp, err := http.Head(siteBaseURL)
if err != nil || resp.StatusCode >= 500 {
    return errors.New("site unreachable before buildId fetch")
}

Try / catch

buildId, err := getBuildId(ctx)
if err != nil {
    if cached := cachedBuildId(); cached != "" {
        buildId = cached
    } else {
        return fmt.Errorf("buildId fetch failed and no cache: %w", err)
    }
}

Prevention

When it happens

Trigger: client.Do fails on all retries: site unreachable, DNS resolution failure, request timeout, TLS error, or context canceled, with buildIdCache empty.

Common situations: Target site down or blocked (region/firewall); no internet/DNS issues in the deployment environment; timeout too aggressive for a slow site; first run without any cached buildId.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at plugin/pansearch/pansearch.go:412

		}

		resp, respErr = p.GetClient().Do(req)
		if respErr == nil && resp.StatusCode == 200 {
			break
		}

		if resp != nil {
			resp.Body.Close()
		}
	}

	// 如果所有重试都失败,但有旧的缓存,使用旧的缓存(优雅降级)
	if respErr != nil || resp == nil {
		if buildIdCache != "" {
			// fmt.Printf("请求失败,使用旧的buildId: %v\n", respErr)
			return buildIdCache, nil
		}
		return "", fmt.Errorf("请求失败: %w", respErr)
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		// 如果状态码不是200,但有旧的缓存,使用旧的缓存(优雅降级)
		if buildIdCache != "" {
			fmt.Printf("获取buildId时服务器返回非200状态码: %d,使用旧的buildId\n", resp.StatusCode)
			return buildIdCache, nil
		}
		return "", fmt.Errorf("获取buildId时服务器返回非200状态码: %d", resp.StatusCode)
	}

	// 使用更高效的方式读取响应体
	var bodyBuilder strings.Builder
	_, err = io.Copy(&bodyBuilder, resp.Body)
	if err != nil {
		// 如果读取响应失败,但有旧的缓存,使用旧的缓存(优雅降级)
		if buildIdCache != "" {

View on GitHub (pinned to beaa561337)