fish2018/pansou · error

备用域名请求也失败

Error message

备用域名请求也失败: %w

What it means

searchPage in the panwiki plugin issues a GET to the primary search URL with redirects disabled. If that transport fails and the plugin has already switched to the backup domain (or the backup retry also fails at the transport level), it wraps the underlying error with "备用域名请求也失败" — meaning both the primary and backup domain requests could not complete (DNS, TLS, timeout, connection reset).

Solutions

  1. Verify network connectivity and DNS resolution for both the primary and backup panwiki domains (curl the base URLs).
  2. Check the wrapped %w error to identify whether it is DNS, TLS, or timeout and fix that specific cause.
  3. Increase the http.Client timeout if it is too aggressive.
  4. Configure/verify the backup domain is correct and currently serving; if the site moved, update PrimaryBaseURL/backup constants.
  5. Add a proxy configuration if the environment requires one for outbound requests.

Example fix

// before
resp, err = client.Do(req)
if err != nil {
    return nil, fmt.Errorf("备用域名请求也失败: %w", err)
}
// after
resp, err = client.Do(req)
if err != nil {
    log.Printf("panwiki: backup domain request failed: %v", err)
    return nil, fmt.Errorf("备用域名请求也失败: %w", err) // caller should inspect errors.Unwrap for cause
}
Defensive patterns

Strategy: retry

Validate before calling

// Go: preflight reachability check
func reachable(u string) bool {
    c := &http.Client{Timeout: 5 * time.Second}
    resp, err := c.Head(u)
    return err == nil && resp.StatusCode < 500
}

Try / catch

results, err := plugin.Search(keyword, page)
if err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) && netErr.Timeout() {
        // retry with backoff or serve cached results
    }
    return fmt.Errorf("search unavailable: %w", err)
}

Prevention

When it happens

Trigger: client.Do on the rebuilt backup-domain URL returns a non-nil error — e.g. the backup domain is unreachable, DNS fails, TLS handshake fails, request times out, or the network is down. Only fires when the primary request already failed and p.currentBaseURL was PrimaryBaseURL so switchToBackupDomain was attempted.

Common situations: Both panwiki domains blocked or down (e.g. GFW/network filtering), offline environment, DNS resolver misconfiguration, corporate proxy blocking outbound HTTPS, overly short client timeout.

Related errors


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

Appendix: source

Thrown at plugin/panwiki/panwiki.go:193

	if err != nil {
		// 如果主域名失败,尝试切换到备用域名
		if p.currentBaseURL == PrimaryBaseURL {
			if p.debugMode {
				log.Printf("[Panwiki] 主域名请求失败,尝试备用域名: %v", err)
			}
			p.switchToBackupDomain()
			
			// 重新构建URL并重试
			initialURL = p.getSearchURL(keyword, page)
			req, err = http.NewRequest("GET", initialURL, nil)
			if err != nil {
				return nil, fmt.Errorf("创建备用域名请求失败: %w", err)
			}
			p.setRequestHeaders(req)
			
			resp, err = client.Do(req)
			if err != nil {
				return nil, fmt.Errorf("备用域名请求也失败: %w", err)
			}
		} else {
			return nil, fmt.Errorf("初始请求失败: %w", err)
		}
	}
	defer resp.Body.Close()
	
	// 重置重定向策略
	client.CheckRedirect = nil
	
	// 获取重定向URL
	location := resp.Header.Get("Location")
	if location == "" {
		return nil, fmt.Errorf("未获取到重定向URL")
	}
	
	// 构建完整的重定向URL
	var searchURL string

View on GitHub (pinned to beaa561337)