chenhg5/cc-connect · error
weixin: %s: new request: %w
Error message
weixin: %s: new request: %w
What it means
post() fails while constructing the outbound HTTP request with http.NewRequestWithContext, before any network I/O. Given that bodies are plain byte slices and endpoints are simple strings, this almost always indicates a malformed URL — e.g. an empty or invalid baseURL joined with the endpoint.
Source
Thrown at platform/weixin/client.go:83
Timeout: timeout + 5*time.Second,
Transport: tr,
}
}
func randomWechatUIN() string {
var b [4]byte
if _, err := rand.Read(b[:]); err != nil {
return base64.StdEncoding.EncodeToString([]byte("0000"))
}
u := uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%d", u)))
}
func (c *apiClient) post(ctx context.Context, endpoint string, body []byte, timeout time.Duration, label string) ([]byte, error) {
url := c.baseURL + strings.TrimPrefix(endpoint, "/")
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return nil, fmt.Errorf("weixin: %s: new request: %w", label, err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("AuthorizationType", "ilink_bot_token")
req.Header.Set("Content-Length", fmt.Sprintf("%d", len(body)))
req.Header.Set("X-WECHAT-UIN", randomWechatUIN())
if c.token != "" {
req.Header.Set("Authorization", "Bearer "+c.token)
}
if c.routeTag != "" {
req.Header.Set("SKRouteTag", c.routeTag)
}
client := c.httpClient
if timeout > 0 {
// Dedicated client so long-poll does not inherit short Timeout from default client.
client = c.longPollClient(timeout)
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Check the base_url setting for the weixin platform in config.toml — it must include the scheme (default https://ilinkai.weixin.qq.com)
- Print/verify the constructed URL (baseURL+endpoint) when this fires
- Ensure endpoint strings have no stray whitespace or invalid characters
- Confirm the label in the error to identify which API call (getUpdates/sendMessage/etc.) built the bad request
Example fix
# before: config.toml [platforms.weixin] base_url = "ilinkai.weixin.qq.com" # missing scheme # after [platforms.weixin] base_url = "https://ilinkai.weixin.qq.com"
Defensive patterns
Strategy: validation
Validate before calling
u := baseURL
if parsed, err := url.Parse(u); err != nil || parsed.Scheme == "" || parsed.Host == "" {
return fmt.Errorf("invalid weixin base_url %q", u)
} Prevention
- Always include the scheme (https://) in base_url in config.toml
- Validate base_url at startup with url.Parse before entering the poll loop
- Stick to the default (omit base_url) unless you have a proxy/gateway requirement
- Trim whitespace/control characters from configured URLs
When it happens
Trigger: http.NewRequestWithContext returns an error for the URL c.baseURL+endpoint — typically an unparseable/empty base URL or a context already cancelled with an invalid method/URL combination.
Common situations: baseURL misconfigured in config.toml (e.g. missing scheme like 'ilinkai.weixin.qq.com' without https://); whitespace/control characters injected into the URL; empty endpoint constant typo.
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
- build request: %w
- reasonix: create request: %w
- http %d: %s
- get_bot_qrcode: %w
- get_qrcode_status http %d: %s
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/87cfb43e149c8c5b.
Report an issue: GitHub.