{"record":{"id":"f2c7a78fec358527","repo":"chenhg5/cc-connect","slug":"create-request-w-f2c7a7","errorCode":null,"errorMessage":"create request: %w","messagePattern":"create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/dingtalk/dingtalk.go","lineNumber":695,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"get access token: %w\", err)\n\t}\n\n\treqBody := map[string]string{\n\t\t\"downloadCode\": downloadCode,\n\t\t\"robotCode\":    p.robotCode,\n\t}\n\tbodyBytes, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"marshal request: %w\", err)\n\t}\n\n\tctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\n\tdefer cancel()\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost,\n\t\t\"https://api.dingtalk.com/v1.0/robot/messageFiles/download\",\n\t\tbytes.NewReader(bodyBytes))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"create request: %w\", err)\n\t}\n\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"x-acs-dingtalk-access-token\", token)\n\n\tresp, err := p.httpClient.Do(req)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"do request: %w\", err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"api returned status %d\", resp.StatusCode)\n\t}\n\n\tvar result downloadResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&result); err != nil {\n\t\treturn \"\", fmt.Errorf(\"decode response: %w\", err)","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/dingtalk/dingtalk.go#L677-L713","documentation":"getDownloadURL wraps http.NewRequestWithContext failure. Creating the POST request to https://api.dingtalk.com/v1.0/robot/messageFiles/download failed — almost always due to an invalid/malformed URL or a nil body reader; with this static, valid URL it should not occur at runtime.","triggerScenarios":"http.NewRequestWithContext(http.MethodPost, \"https://api.dingtalk.com/v1.0/robot/messageFiles/download\", bytes.NewReader(bodyBytes)) returned an error.","commonSituations":"Essentially never in production with the hardcoded URL; would appear only if the code/build was altered (e.g. URL constructed from bad config) or the Go runtime/environment is corrupt.","solutions":["Verify the build is unmodified and the hardcoded endpoint URL is intact.","If the URL was parameterized in a fork, validate/percent-encode it before passing to NewRequest.","No config change prevents this; treat as an internal bug and report with the wrapped cause."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// If the URL ever becomes configurable, pre-validate it:\nif u, err := url.Parse(downloadAPIEndpoint); err != nil || u.Scheme != \"https\" || u.Host == \"\" {\n    log.Fatal(\"invalid dingtalk download endpoint\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"create request\") {\n    log.Error(\"dingtalk: malformed request construction (bug)\", \"err\", err)\n    return err\n}","preventionTips":["Keep the endpoint URL static and vetted","If parameterizing the URL, validate with url.Parse first","Never pass a nil reader to NewRequest for POSTs"],"tags":["dingtalk","http","request","api"],"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"}