{"record":{"id":"caeb648d1e35bbbb","repo":"chenhg5/cc-connect","slug":"s-cdn-upload-failed-after-d-attempts","errorCode":null,"errorMessage":"%s: CDN upload failed after %d attempts","messagePattern":"(.+?): CDN upload failed after (.+?) attempts","errorType":"http","errorClass":null,"httpStatus":null,"severity":"info","filePath":"platform/weixin/cdn.go","lineNumber":225,"sourceCode":"\t\t\tif msg == \"\" {\n\t\t\t\tmsg = fmt.Sprintf(\"status %d\", resp.StatusCode)\n\t\t\t}\n\t\t\tlastErr = fmt.Errorf(\"%s: CDN upload server error: %s\", label, msg)\n\t\t\tslog.Warn(\"weixin: CDN upload server error\", \"label\", label, \"attempt\", attempt, \"error\", lastErr)\n\t\t\tcontinue\n\t\t}\n\t\tdl := resp.Header.Get(\"x-encrypted-param\")\n\t\tif dl == \"\" {\n\t\t\tlastErr = fmt.Errorf(\"%s: CDN response missing x-encrypted-param\", label)\n\t\t\tslog.Warn(\"weixin: CDN upload bad response\", \"label\", label, \"attempt\", attempt)\n\t\t\tcontinue\n\t\t}\n\t\treturn dl, nil\n\t}\n\tif lastErr != nil {\n\t\treturn \"\", fmt.Errorf(\"%s: CDN upload failed after %d attempts: %w\", label, cdnUploadMaxRetries, lastErr)\n\t}\n\treturn \"\", fmt.Errorf(\"%s: CDN upload failed after %d attempts\", label, cdnUploadMaxRetries)\n}\n\nfunc md5Hex(b []byte) string {\n\th := md5.Sum(b)\n\treturn hex.EncodeToString(h[:])\n}\n\nfunc detectImageMime(b []byte) string {\n\tif len(b) >= 3 && b[0] == 0xFF && b[1] == 0xD8 && b[2] == 0xFF {\n\t\treturn \"image/jpeg\"\n\t}\n\tif len(b) >= 8 && string(b[0:8]) == \"\\x89PNG\\r\\n\\x1a\\n\" {\n\t\treturn \"image/png\"\n\t}\n\tif len(b) >= 6 && (string(b[0:6]) == \"GIF87a\" || string(b[0:6]) == \"GIF89a\") {\n\t\treturn \"image/gif\"\n\t}\n\tif len(b) >= 12 && string(b[0:4]) == \"RIFF\" && string(b[8:12]) == \"WEBP\" {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/weixin/cdn.go#L207-L243","documentation":"The degenerate branch of uploadBufferToCDN's post-loop return: reached only when the retry loop completes with lastErr == nil, which cannot normally happen (every non-success path sets lastErr). It returns the same 'failed after N attempts' message but without a wrapped cause.","triggerScenarios":"Logically unreachable; would require the retry loop to finish all 3 attempts without setting lastErr and without returning, e.g. if the success return were removed or the loop counter were 0.","commonSituations":"Effectively never seen in production; exists as a compile-safe final return for the compiler.","solutions":["If ever observed, treat it as an internal invariant violation and report it — inspect the loop logic in platform/weixin/cdn.go","Add defensive logging/reporting around uploads so the absence of any attempt-level warning is visible"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasSuffix(err.Error(), \"CDN upload failed after 3 attempts\") && !strings.Contains(err.Error(), \": \") {\n    // no wrapped cause: log as potential invariant violation with full context\n}","preventionTips":["Report occurrences upstream — this branch is logically unreachable","Keep attempt-level slog.Warn lines enabled so the real cause is always visible","Add a test asserting every failed loop iteration sets lastErr"],"tags":["cdn","upload","invariant","weixin"],"backgroundTag":"internal-invariant-violation","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"}