fish2018/pansou · error

创建请求失败

Error message

创建请求失败: %w

What it means

findPotentialActionIDs failed while constructing the GET request to the site homepage via http.NewRequest("GET", BaseURL, nil). This only fails if BaseURL cannot be parsed into a valid URL (url.Parse error), since a plain GET with nil body has no other construction failure mode.

Solutions

  1. Print/log BaseURL and validate it parses (url.Parse) with a scheme like https://.
  2. Fix the misconfigured base URL value in config/env.
  3. If BaseURL is a constant, verify it was not corrupted by local edits or build flags.
  4. Sanitize/trim the URL before use: strings.TrimSpace and url.Parse check at plugin init.

Example fix

// before
req, err := http.NewRequest("GET", BaseURL, nil)
if err != nil {
    return nil, fmt.Errorf("创建请求失败: %w", err)
}
// after
base := strings.TrimSpace(BaseURL)
if u, perr := url.Parse(base); perr != nil || u.Scheme == "" || u.Host == "" {
    return nil, fmt.Errorf("无效的BaseURL %q: %w", base, perr)
}
req, err := http.NewRequest("GET", base, nil)
if err != nil {
    return nil, fmt.Errorf("创建请求失败: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(strings.TrimSpace(BaseURL))
if err != nil || u.Scheme == "" || u.Host == "" {
    return fmt.Errorf("BaseURL %q is not a valid absolute URL", BaseURL)
}

Type guard

func validURL(s string) bool {
    u, err := url.Parse(strings.TrimSpace(s))
    return err == nil && u.Scheme != "" && u.Host != ""
}

Try / catch

results, err := plugin.Search(kw)
if err != nil && strings.Contains(err.Error(), "创建请求失败") {
    log.Fatalf("panyq BaseURL misconfigured: %v", err)
}

Prevention

When it happens

Trigger: Any call chain starting discovery (findPotentialActionIDs ← discoverActionIDs ← doSearch/getOrDiscoverActionIDs) when the BaseURL constant is malformed — e.g. built from a misconfigured/overridden base URL containing spaces or invalid characters.

Common situations: Misconfigured base URL override (env var or config) with typos, whitespace, or missing scheme; corrupted build-time constant; concatenating a path onto BaseURL incorrectly producing an unparseable URL.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at plugin/panyq/panyq.go:651

		// 继续执行,不返回错误
	}
	
	if DebugLog {
		fmt.Println("panyq: all Action IDs validated successfully:")
		for _, key := range ActionIDKeys {
			fmt.Printf("panyq:   %s = %s\n", key, finalIDs[key])
		}
	}
	
	return finalIDs, nil
}

// findPotentialActionIDs 从网站获取潜在的Action ID
func (p *PanyqPlugin) findPotentialActionIDs(client *http.Client) ([]string, error) {
	// 请求网站首页
	req, err := http.NewRequest("GET", BaseURL, nil)
	if err != nil {
		return nil, fmt.Errorf("创建请求失败: %w", err)
	}
	
	// 只保留指定的请求头
	// req.Header.Set("sec-ch-ua", `"Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"`)
	req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36")
	
	// 发送请求
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("请求网站首页失败: %w", err)
	}
	defer resp.Body.Close()
	
	// 检查状态码
	if resp.StatusCode != http.StatusOK {
		// 读取响应体以获取服务器返回的具体错误信息
		bodyBytes, err := io.ReadAll(resp.Body)
		if err != nil {

View on GitHub (pinned to beaa561337)