fish2018/pansou · error

站点地址格式错误

Error message

站点地址格式错误: %v

What it means

URL parse error in gying's normalizeBaseURL (plugin/gying/gying.go:606): after scheme defaulting, net/url could not parse the configured site address. Means the configured base URL is syntactically invalid (bad characters/format), not merely unreachable.

Solutions

  1. Paste the address into a browser address bar first — if it does not resolve there, fix it.
  2. Remove whitespace/control characters and re-encode special characters.
  3. Ensure the value is a bare origin like https://host[:port] with no junk characters.

Example fix

// before
"site": "https://exa mple.com"
// after
"site": "https://example.com"
Defensive patterns

Strategy: validation

Validate before calling

site := strings.TrimSpace(cfg.Site)
if u, err := url.Parse(site); err != nil || u.Scheme == "" {
    if _, err2 := url.Parse("https://" + site); err2 != nil {
        return fmt.Errorf("gying site address is not a valid URL: %v", err2)
    }
}

Try / catch

if err := plugin.Configure(cfg); err != nil {
    if strings.Contains(err.Error(), "站点地址格式错误") {
        return fmt.Errorf("fix the gying site URL in config: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: normalizeBaseURL: after prepending "https://" when the scheme prefix was missing, url.Parse returned a non-nil error (e.g. control characters, invalid percent-encodings, spaces in host).

Common situations: 用户在配置文件中粘贴了带空格或换行的地址;地址被截断。

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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

Appendix: source

Thrown at plugin/gying/gying.go:606

		BaseAsyncPlugin: plugin.NewBaseAsyncPlugin("gying", 3),
	}

	plugin.RegisterGlobalPlugin(p)
}

func normalizeBaseURL(raw string) (string, error) {
	baseURL := strings.TrimSpace(raw)
	baseURL = strings.TrimRight(baseURL, "/")
	if baseURL == "" {
		return "", fmt.Errorf("站点地址不能为空")
	}
	if !strings.HasPrefix(baseURL, "http://") && !strings.HasPrefix(baseURL, "https://") {
		baseURL = "https://" + baseURL
	}

	parsed, err := url.Parse(baseURL)
	if err != nil {
		return "", fmt.Errorf("站点地址格式错误: %v", err)
	}
	if parsed.Scheme != "http" && parsed.Scheme != "https" {
		return "", fmt.Errorf("站点地址必须以 http:// 或 https:// 开头")
	}
	if parsed.Host == "" {
		return "", fmt.Errorf("站点地址缺少域名")
	}
	if parsed.RawQuery != "" || parsed.Fragment != "" {
		return "", fmt.Errorf("站点地址不能包含参数或锚点")
	}
	if parsed.Path != "" && parsed.Path != "/" {
		return "", fmt.Errorf("站点地址不能包含路径")
	}

	// HTTP clients do not consistently convert Unicode hostnames to IDNA.
	// Store the ASCII form so both the config page and requests are reliable.
	hostname, err := idna.Lookup.ToASCII(parsed.Hostname())
	if err != nil {

View on GitHub (pinned to beaa561337)