{"record":{"id":"6ef28ce78016ac20","repo":"chenhg5/cc-connect","slug":"weixin-empty-image","errorCode":null,"errorMessage":"weixin: empty image","messagePattern":"weixin: empty image","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/weixin/media_outbound.go","lineNumber":170,"sourceCode":"\nfunc buildVideoMessageItem(ref *cdnUploadedRef) messageItem {\n\treturn messageItem{\n\t\tType: messageItemVideo,\n\t\tVideoItem: &videoItem{\n\t\t\tMedia:     mediaFromUploadRef(ref),\n\t\t\tVideoSize: ref.cipherSize,\n\t\t},\n\t}\n}\n\n// SendImage implements core.ImageSender.\nfunc (p *Platform) SendImage(ctx context.Context, replyCtx any, img core.ImageAttachment) error {\n\trc, err := p.resolveReplyContext(replyCtx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(img.Data) == 0 {\n\t\treturn fmt.Errorf(\"weixin: empty image\")\n\t}\n\tref, err := p.uploadToWeixinCDN(ctx, rc.peerUserID, img.Data, uploadMediaImage, \"SendImage\")\n\tif err != nil {\n\t\treturn err\n\t}\n\titem := messageItem{\n\t\tType: messageItemImage,\n\t\tImageItem: &imageItem{\n\t\t\tMedia: &cdnMedia{\n\t\t\t\tEncryptQueryParam: ref.downloadParam,\n\t\t\t\tAESKey:            formatAesKeyForAPI(ref.aesKey),\n\t\t\t\tEncryptType:       1,\n\t\t\t},\n\t\t\tMidSize: ref.cipherSize,\n\t\t},\n\t}\n\treturn p.sendSingleItem(ctx, rc, item)\n}","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/weixin/media_outbound.go#L152-L188","documentation":"Validation guard in Weixin SendImage: the image attachment's Data slice has zero length, so there are no bytes to upload to the WeChat CDN; the caller produced an empty image attachment.","triggerScenarios":"Calling SendImage with core.ImageAttachment{Data: nil} or Data: []byte{}.","commonSituations":"Agent produced an image attachment whose bytes failed to load (screenshot tool returned nothing); upstream decode path swallowed an error and returned empty data.","solutions":["Ensure the image bytes are populated (len(img.Data) > 0) before calling SendImage.","Fix the upstream generation/download step that produced empty image data.","Guard at the call site: skip or error out early when image data is empty."],"exampleFix":"// before\ndata, _ := renderScreenshot() // error ignored, data empty\np.SendImage(ctx, rc, core.ImageAttachment{Data: data}) // weixin: empty image\n// after\ndata, err := renderScreenshot()\nif err != nil || len(data) == 0 { return fmt.Errorf(\"screenshot: %w\", err) }","handlingStrategy":"validation","validationCode":"if len(img.Data) == 0 { return errors.New(\"image attachment is empty; skipping send\") }","typeGuard":null,"tryCatchPattern":"if err := p.SendImage(ctx, rc, img); err != nil && strings.Contains(err.Error(), \"empty image\") { log.Error(\"empty image produced by upstream render step\") }","preventionTips":["Check image byte length before every SendImage call","Surface render/screenshot errors instead of dropping them","Unit-test the attachment pipeline with real bytes"],"tags":["weixin","image","validation","empty-data"],"backgroundTag":"empty-required-field","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"}