{"record":{"id":"e7725531726832a1","repo":"chenhg5/cc-connect","slug":"download-file-s-w","errorCode":null,"errorMessage":"download file %s: %w","messagePattern":"download file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1362,"sourceCode":"\nfunc (p *Platform) downloadFile(fileID string) ([]byte, error) {\n\tbot, err := p.connectedBot(\"download file\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tctx := context.Background()\n\tf, err := bot.GetFile(ctx, &tgbot.GetFileParams{FileID: fileID})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get file: %w\", err)\n\t}\n\tif f.FilePath == \"\" {\n\t\treturn nil, fmt.Errorf(\"get file: empty file_path returned for file_id %s\", fileID)\n\t}\n\tlink := bot.FileDownloadLink(f)\n\n\tresp, err := p.httpClient.Get(link)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"download file %s: %w\", fileID, err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"download file %s: status %d\", fileID, resp.StatusCode)\n\t}\n\treturn io.ReadAll(resp.Body)\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// Formats:\n\t//   telegram:{chatID}                      - shared session, no topic\n\t//   telegram:{chatID}:{threadID}           - shared session, with topic\n\t//   telegram:{chatID}:{userID}             - per-user session, no topic\n\t//   telegram:{chatID}:{threadID}:{userID}  - per-user session, with topic\n\tparts := strings.SplitN(sessionKey, \":\", 5)\n\tif len(parts) < 2 || parts[0] != \"telegram\" {\n\t\treturn nil, fmt.Errorf(\"telegram: invalid session key %q\", sessionKey)\n\t}","sourceCodeStart":1344,"sourceCodeEnd":1380,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1344-L1380","documentation":"Returned when the HTTP GET to the Telegram file download URL (built from FileDownloadLink) fails at the transport level. The getFile step succeeded and a link was produced, but the actual byte transfer could not be performed or completed.","triggerScenarios":"p.httpClient.Get(link) returns a non-nil err: DNS failure, connection refused/reset, TLS error, timeout, or context cancellation while downloading from the file host.","commonSituations":"Outbound network restrictions in containerized deployments; long downloads hitting the http.Client timeout; api.telegram.org blocked in the host region (common where Telegram is filtered); transient server resets.","solutions":["Check outbound network/DNS from the host running the bot; ensure api.telegram.org is reachable.","Increase p.httpClient Timeout for large media downloads.","Configure an HTTP proxy if Telegram is blocked in the deployment region.","Retry with backoff on transient transport errors."],"exampleFix":"// before\np.httpClient = &http.Client{}\n// after: longer timeout for file downloads\np.httpClient = &http.Client{Timeout: 120 * time.Second}","handlingStrategy":"retry","validationCode":"// preflight connectivity\nresp, err := p.httpClient.Get(\"https://api.telegram.org\")\nif err != nil { /* network unavailable */ }","typeGuard":null,"tryCatchPattern":"resp, err := p.httpClient.Get(link)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) { /* increase timeout */ }\n    return nil, fmt.Errorf(\"download file %s: %w\", fileID, err)\n}","preventionTips":["Set a generous http.Client timeout for media downloads","Verify outbound access to api.telegram.org from the deployment host","Configure a proxy where Telegram is blocked","Retry transport errors with exponential backoff"],"tags":["telegram","http","file-download","network"],"backgroundTag":"network-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}