fish2018/pansou · error

初始请求失败

Error message

初始请求失败: %w

What it means

searchPage disables automatic redirects and expects the first response to be a redirect. If the FIRST request to the primary domain fails at the transport level while p.currentBaseURL is NOT the primary domain (i.e. the plugin is already on the backup domain), there is no second domain to fall back to, so it returns "初始请求失败" wrapping the client.Do error.

Solutions

  1. Inspect the wrapped error (errors.Unwrap) to identify the transport failure cause.
  2. Check reachability of the current base URL with curl/ping.
  3. Reset or restart the plugin to retry the primary domain if it has recovered.
  4. Increase client timeout or configure a proxy if the network path requires it.
Defensive patterns

Strategy: retry

Validate before calling

// Go: verify the current base URL resolves before searching
if net.ParseIP("") == nil {
    if _, err := net.LookupHost(strings.TrimPrefix(p.currentBaseURL, "https://")); err != nil {
        return nil, fmt.Errorf("current base URL unreachable: %w", err)
    }
}

Try / catch

results, err := plugin.Search(keyword, page)
if err != nil {
    if strings.Contains(err.Error(), "初始请求失败") {
        // fall back to another data source or serve cached results
    }
    return err
}

Prevention

When it happens

Trigger: client.Do(req) on the initial search URL returns an error AND p.currentBaseURL != PrimaryBaseURL (the plugin is already using the backup domain), so the else branch executes. Causes: DNS failure, timeout, TLS errors, connection refused against the backup domain.

Common situations: Backup domain itself is down or blocked; persistent outage after an earlier failover; network offline; DNS cannot resolve the backup domain.

Related errors


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

Appendix: source

Thrown at plugin/panwiki/panwiki.go:196

			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
	if strings.HasPrefix(location, "http") {
		searchURL = location
	} else {

View on GitHub (pinned to beaa561337)