{"record":{"id":"ac3ad21c463b0d78","repo":"chenhg5/cc-connect","slug":"weixin-cdn-base-url-is-empty","errorCode":null,"errorMessage":"weixin: cdn_base_url is empty","messagePattern":"weixin: cdn_base_url is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/weixin/media_outbound.go","lineNumber":60,"sourceCode":"\trc, ok := replyCtx.(*replyContext)\n\tif !ok || rc == nil {\n\t\treturn nil, fmt.Errorf(\"weixin: invalid reply context\")\n\t}\n\tif strings.TrimSpace(rc.contextToken) == \"\" {\n\t\trc.contextToken = p.getContextToken(rc.peerUserID)\n\t}\n\tif strings.TrimSpace(rc.contextToken) == \"\" {\n\t\treturn nil, fmt.Errorf(\"weixin: missing context_token for peer %q\", rc.peerUserID)\n\t}\n\treturn rc, nil\n}\n\nfunc (p *Platform) uploadToWeixinCDN(ctx context.Context, to string, plaintext []byte, mediaType int, label string) (*cdnUploadedRef, error) {\n\tif len(plaintext) == 0 {\n\t\treturn nil, fmt.Errorf(\"weixin: %s: empty payload\", label)\n\t}\n\tif strings.TrimSpace(p.cdnBaseURL) == \"\" {\n\t\treturn nil, fmt.Errorf(\"weixin: cdn_base_url is empty\")\n\t}\n\trawSize := len(plaintext)\n\taesKey := make([]byte, 16)\n\tif _, err := rand.Read(aesKey); err != nil {\n\t\treturn nil, fmt.Errorf(\"weixin: %s: aes key: %w\", label, err)\n\t}\n\tfilekey := randomHex(16)\n\treq := getUploadURLRequest{\n\t\tFilekey:     filekey,\n\t\tMediaType:   mediaType,\n\t\tToUserID:    to,\n\t\tRawsize:     rawSize,\n\t\tRawfilemd5:  md5Hex(plaintext),\n\t\tFilesize:    aesECBPaddedSize(rawSize),\n\t\tNoNeedThumb: true,\n\t\tAeskey:      hex.EncodeToString(aesKey),\n\t}\n\tresp, err := p.api.getUploadURL(ctx, req)","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/weixin/media_outbound.go#L42-L78","documentation":"The CDN upload endpoint base URL (p.cdnBaseURL) is blank, so uploadToWeixinCDN cannot construct the upload request. This is a configuration problem: the WeChat work-platform CDN base URL was never set.","triggerScenarios":"Any SendImage/SendFile/SendAudio call when the platform config omitted cdn_base_url or set it to whitespace.","commonSituations":"config.toml missing the cdn_base_url key; copy-pasted an example config that leaves it empty; environment-specific config for production WeChat CDN not filled in.","solutions":["Set cdn_base_url in the weixin platform section of config.toml to the correct WeChat CDN endpoint.","Validate config at startup (fail fast) so media sends never reach upload with an empty base URL.","Check for whitespace-only values; the check uses TrimSpace, so \" \" still counts as empty."],"exampleFix":"// before (config.toml)\n# cdn_base_url = \"\"\n// after (config.toml)\ncdn_base_url = \"https://login.weixin.qq.com\"  # actual WeChat CDN base URL","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(cfg.Weixin.CDNBaseURL) == \"\" { return errors.New(\"weixin.cdn_base_url must be set in config.toml\") }","typeGuard":null,"tryCatchPattern":"if err := p.SendImage(ctx, rc, img); err != nil && strings.Contains(err.Error(), \"cdn_base_url is empty\") { log.Fatal(\"weixin platform misconfigured: set cdn_base_url\") }","preventionTips":["Validate the full weixin config at startup, before any sends","Include cdn_base_url in your config template/example","Fail fast on empty required config strings (TrimSpace check)"],"tags":["weixin","media","configuration","cdn"],"backgroundTag":"missing-required-config","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"}