sipeed/picoclaw · error

invalid WeCom QR page URL: %w

Error message

invalid WeCom QR page URL: %w

What it means

url.Parse rejected opts.QRCodePageURL in buildWeComQRCodePageURL, which builds the human-clickable page URL (source + sourceID + scode) printed next to the rendered QR. Failures are the same rare class as 133/134: an unparseable base URL from a custom option, config override, or test stub — the defaults (wecomQRPageEndpoint) are valid constants.

Source

Thrown at cmd/picoclaw/internal/auth/wecom.go:378

}

func buildWeComQRQueryURL(baseURL, scode string) (string, error) {
	u, err := url.Parse(baseURL)
	if err != nil {
		return "", fmt.Errorf("invalid WeCom QR query URL: %w", err)
	}

	query := u.Query()
	query.Set("scode", scode)
	u.RawQuery = query.Encode()

	return u.String(), nil
}

func buildWeComQRCodePageURL(baseURL, sourceID, scode string) (string, error) {
	u, err := url.Parse(baseURL)
	if err != nil {
		return "", fmt.Errorf("invalid WeCom QR page URL: %w", err)
	}

	query := u.Query()
	query.Set("source", sourceID)
	query.Set("sourceID", sourceID)
	query.Set("scode", scode)
	u.RawQuery = query.Encode()

	return u.String(), nil
}

func doWeComJSONGet(ctx context.Context, client *http.Client, targetURL string, out any) error {
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, targetURL, nil)
	if err != nil {
		return err
	}

	resp, err := client.Do(req)

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Validate QRCodePageURL the same way as the other two endpoints before starting the flow
  2. Prefer library defaults; only override with a known-good absolute URL
  3. Sanitize any env-sourced URL (trim spaces/newlines)
  4. Test custom URLs with url.Parse in a unit test for your configuration layer
Defensive patterns

Strategy: validation

Validate before calling

if _, err := url.Parse(opts.QRCodePageURL); err != nil {
	return fmt.Errorf("QRCodePageURL %q is not a valid URL: %w", opts.QRCodePageURL, err)
}

Type guard

func isInvalidURL(err error) bool {
	return err != nil && strings.Contains(err.Error(), "invalid URL")
}

Prevention

When it happens

Trigger: Custom QRCodePageURL containing control characters or invalid escapes; overrides sourced from env vars with embedded whitespace/newlines; programmatic option construction with unvalidated input.

Common situations: Self-hosted relay page URL typo; fork customizing the page endpoint; CI test doubles with sloppy URLs.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/22b0fded10652beb. Report an issue: GitHub.