fish2018/pansou · error

[ ] 搜索请求失败

Error message

[%s] 搜索请求失败: %w

What it means

searchImpl in the cyg plugin wraps any failure from fetchSearchResults with this error, prefixed with the plugin name. It is a generic wrapper: the root cause is in the wrapped error (request creation, HTTP failure, bad status, read or JSON errors). The WordPress REST search query itself could not be completed.

Solutions

  1. Unwrap the error (%w) to find the root cause; each underlying error has its own fix.
  2. Test the constructed search URL directly in a browser/curl to confirm the REST endpoint responds.
  3. Verify network connectivity and DNS for cygBaseURL from the host running the code.
  4. Confirm the upstream still supports /wp-json/wp/v2/posts with the given per_page/orderby/order/page parameters.
Defensive patterns

Strategy: try-catch

Try / catch

results, err := plugin.SearchWithResult(ctx, opts)
if err != nil {
    var wrapped interface{ Unwrap() error }
    log.Printf("cyg search failed: %v (cause: %v)", err, errors.Unwrap(err))
    // decide retry vs fallback based on the unwrapped cause
}

Prevention

When it happens

Trigger: Any call path through SearchWithResult → searchImpl where fetchSearchResults returns an error: invalid search URL construction, network failure, non-200 status, body read failure, or JSON decode failure of the /wp-json/wp/v2/posts response.

Common situations: Upstream WordPress site is down or moved; keyword contains characters that break the URL; network/firewall blocks the request; the site no longer exposes the REST API.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at plugin/cyg/cyg.go:115

// SearchWithResult 执行搜索并返回包含IsFinal标记的结果(推荐方法)
func (p *CygPlugin) SearchWithResult(keyword string, ext map[string]interface{}) (model.PluginSearchResult, error) {
	return p.AsyncSearchWithResult(keyword, p.searchImpl, p.MainCacheKey, ext)
}

// searchImpl 搜索实现逻辑
func (p *CygPlugin) searchImpl(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {
	// 解析扩展参数
	opts := p.parseExtOptions(ext)

	// 1. 构建搜索URL
	searchURL := fmt.Sprintf(cygBaseURL+"/wp-json/wp/v2/posts?per_page=%d&orderby=%s&order=%s&page=%d&search=%s",
		opts.PerPage, opts.OrderBy, opts.Order, opts.Page, url.QueryEscape(keyword))

	// 2. 发送搜索请求
	posts, err := p.fetchSearchResults(client, searchURL)
	if err != nil {
		return nil, fmt.Errorf("[%s] 搜索请求失败: %w", p.Name(), err)
	}

	if len(posts) == 0 {
		return []model.SearchResult{}, nil
	}

	// 3. 并发获取每个帖子的下载链接
	results := p.fetchDownloadLinksAsync(client, posts, keyword)

	// 4. 关键词过滤
	filteredResults := plugin.FilterResultsByKeyword(results, keyword)

	return filteredResults, nil
}

// fetchSearchResults 获取搜索结果列表
func (p *CygPlugin) fetchSearchResults(client *http.Client, searchURL string) ([]CygPost, error) {
	// 创建带超时的上下文

View on GitHub (pinned to beaa561337)