{"record":{"id":"e4993b0ddd63fa3b","repo":"chenhg5/cc-connect","slug":"yuanbao-create-request-w","errorCode":null,"errorMessage":"yuanbao: create request: %w","messagePattern":"yuanbao: create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/sign.go","lineNumber":141,"sourceCode":"\t\t}\n\t\tnonceBytes := make([]byte, 16)\n\t\tif _, err := rand.Read(nonceBytes); err != nil {\n\t\t\tlastErr = fmt.Errorf(\"yuanbao: generate nonce: %w\", err)\n\t\t\tcontinue\n\t\t}\n\t\tnonce := hex.EncodeToString(nonceBytes)\n\t\ttimestamp := buildTimestamp()\n\t\tsignature := computeSignature(nonce, timestamp, appKey, appSecret)\n\n\t\tpayload := map[string]string{\n\t\t\t\"app_key\": appKey, \"nonce\": nonce,\n\t\t\t\"signature\": signature, \"timestamp\": timestamp,\n\t\t}\n\t\tbody, _ := json.Marshal(payload)\n\n\t\treq, err := http.NewRequest(\"POST\", urlStr, strings.NewReader(string(body)))\n\t\tif err != nil {\n\t\t\tlastErr = fmt.Errorf(\"yuanbao: create request: %w\", err)\n\t\t\tcontinue\n\t\t}\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\treq.Header.Set(\"X-AppVersion\", \"cc-connect-yuanbao/1.0.0\")\n\t\treq.Header.Set(\"X-Instance-Id\", fmt.Sprintf(\"%d\", instanceID))\n\t\treq.Header.Set(\"X-Bot-Version\", \"cc-connect-yuanbao/1.0.0\")\n\t\tif routeEnv != \"\" {\n\t\t\treq.Header.Set(\"X-Route-Env\", routeEnv)\n\t\t}\n\n\t\tresp, err := client.Do(req)\n\t\tif err != nil {\n\t\t\tlastErr = fmt.Errorf(\"yuanbao: request failed: %w\", err)\n\t\t\tcontinue\n\t\t}\n\t\trespBody, _ := io.ReadAll(resp.Body)\n\t\t_ = resp.Body.Close()\n\t\tif resp.StatusCode != http.StatusOK {","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/sign.go#L123-L159","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\napiDomain = \"https://yuanbao.example.com/\\n\"\n// after\napiDomain = strings.TrimSpace(\"https://yuanbao.example.com/\")","handlingStrategy":"validation","validationCode":"if u, err := url.Parse(apiDomain); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid api_domain %q: %w\", apiDomain, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["network","http","config","url"],"backgroundTag":"invalid-url","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}