chenhg5/cc-connect · error
yuanbao: create request: %w
Error message
yuanbao: create request: %w
What it means
fetchToken in the yuanbao platform adapter failed to construct the outbound HTTP POST to the sign-token API (http.NewRequest returned an error). This wraps the underlying net/http error and is stored as lastErr while the retry loop continues to the next attempt. It almost always indicates a malformed URL rather than a transient network problem.
Source
Thrown at platform/yuanbao/sign.go:141
}
nonceBytes := make([]byte, 16)
if _, err := rand.Read(nonceBytes); err != nil {
lastErr = fmt.Errorf("yuanbao: generate nonce: %w", err)
continue
}
nonce := hex.EncodeToString(nonceBytes)
timestamp := buildTimestamp()
signature := computeSignature(nonce, timestamp, appKey, appSecret)
payload := map[string]string{
"app_key": appKey, "nonce": nonce,
"signature": signature, "timestamp": timestamp,
}
body, _ := json.Marshal(payload)
req, err := http.NewRequest("POST", urlStr, strings.NewReader(string(body)))
if err != nil {
lastErr = fmt.Errorf("yuanbao: create request: %w", err)
continue
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-AppVersion", "cc-connect-yuanbao/1.0.0")
req.Header.Set("X-Instance-Id", fmt.Sprintf("%d", instanceID))
req.Header.Set("X-Bot-Version", "cc-connect-yuanbao/1.0.0")
if routeEnv != "" {
req.Header.Set("X-Route-Env", routeEnv)
}
resp, err := client.Do(req)
if err != nil {
lastErr = fmt.Errorf("yuanbao: request failed: %w", err)
continue
}
respBody, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close()
if resp.StatusCode != http.StatusOK {View on GitHub (pinned to 4000b2338a)
Solutions
- Check the api_domain value in config.toml; strip whitespace and ensure it is a valid absolute URL with http(s) scheme.
- Run `cc-connect yuanbao setup` to validate the token/domain before starting the platform; the error is surfaced there too.
- Inspect the wrapped error (%w target) for the exact url.Parse failure message, e.g. `net/http: invalid control character in URL`.
- If the domain is correct but the code builds the URL, log urlStr before http.NewRequest to see the malformed value.
Example fix
// before
apiDomain = "https://yuanbao.example.com/\n"
// after
apiDomain = strings.TrimSpace("https://yuanbao.example.com/") Defensive patterns
Strategy: validation
Validate before calling
if u, err := url.Parse(apiDomain); err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("invalid api_domain %q: %w", apiDomain, err)
} Prevention
- Trim and validate api_domain with url.Parse at config load time
- Reject config values containing control characters or newlines
- Run `cc-connect yuanbao setup` before starting the daemon
When it happens
Trigger: Calling fetchToken (directly or via getToken / VerifyCredentials) with an apiDomain that produces an unparseable URL string passed to http.NewRequest("POST", urlStr, ...) — e.g. a control character or invalid scheme in the configured domain.
Common situations: Config mistake: bot_token configured with surrounding whitespace/control chars, or api_domain in config.toml containing a trailing newline, embedded spaces, or a scheme-less garbage value pasted from a doc.
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
- reasonix: create request: %w
- create request: %w
- gemini stt: create request: %w
- range chunk retries exhausted
- request usage endpoint: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/e4993b0ddd63fa3b.
Report an issue: GitHub.