{"record":{"id":"273b005568c2910d","repo":"chenhg5/cc-connect","slug":"googlechat-upload-create-metadata-part-w","errorCode":null,"errorMessage":"googlechat: upload: create metadata part: %w","messagePattern":"googlechat: upload: create metadata part: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"platform/googlechat/googlechat.go","lineNumber":460,"sourceCode":"}\n\nfunc (p *Platform) Reply(ctx context.Context, rctx any, content string) error {\n\treturn p.post(ctx, rctx, content)\n}\n\nfunc (p *Platform) Send(ctx context.Context, rctx any, content string) error {\n\treturn p.post(ctx, rctx, content)\n}\n\n// uploadAttachment uploads raw bytes to the Chat media endpoint using a\n// multipart/related request and returns the attachmentDataRef resource name.\nfunc (p *Platform) uploadAttachment(ctx context.Context, space, filename, mimeType string, data []byte) (string, error) {\n\tbuf := bytes.NewBuffer(make([]byte, 0, 256+len(data)))\n\tmw := multipart.NewWriter(buf)\n\n\tmetaPart, err := mw.CreatePart(textproto.MIMEHeader{\"Content-Type\": {\"application/json; charset=UTF-8\"}})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"googlechat: upload: create metadata part: %w\", err)\n\t}\n\tif err := json.NewEncoder(metaPart).Encode(map[string]string{\"filename\": filename}); err != nil {\n\t\treturn \"\", fmt.Errorf(\"googlechat: upload: encode metadata: %w\", err)\n\t}\n\n\tmediaPart, err := mw.CreatePart(textproto.MIMEHeader{\"Content-Type\": {mimeType}})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"googlechat: upload: create media part: %w\", err)\n\t}\n\tif _, err := mediaPart.Write(data); err != nil {\n\t\treturn \"\", fmt.Errorf(\"googlechat: upload: write media: %w\", err)\n\t}\n\tif err := mw.Close(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"googlechat: upload: finalize multipart body: %w\", err)\n\t}\n\n\tuploadURL := chatUploadBase + space + \"/attachments:upload?uploadType=multipart\"\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, uploadURL, buf)","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/googlechat/googlechat.go#L442-L478","documentation":"Returned by uploadAttachment when multipart.Writer.CreatePart fails while creating the JSON metadata part of a multipart/related upload body. CreatePart only fails if the MIME header is invalid; since the header here is a hardcoded constant, this error is practically unreachable and indicates an internal invariant violation. It is wrapped with googlechat: context and surfaces via postAttachment (SendImage/SendFile).","triggerScenarios":"Calling SendImage() or SendFile(); during multipart body construction the CreatePart call for the application/json metadata part returns an error — essentially only if the textproto.MIMEHeader constant were malformed.","commonSituations":"Effectively never hit in production; would only appear after a code change that builds the header dynamically with invalid header names/values.","solutions":["Verify you are on an unmodified version of the library; this is a hardcoded valid header.","If reproducible after local modification, inspect the MIME header passed to CreatePart for invalid characters or empty keys.","Report as a bug with the full error chain if it occurs on stock code."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"name, err := p.SendFile(ctx, target, file)\nif err != nil {\n    if strings.Contains(err.Error(), \"create metadata part\") {\n        // internal invariant violation; not caller-recoverable\n        return fmt.Errorf(\"library bug: %w\", err)\n    }\n    return err\n}","preventionTips":["Do not modify the multipart header construction in library code.","Report occurrences upstream as bugs rather than working around them.","Pin library versions and review diffs before upgrading locally patched code."],"tags":["googlechat","upload","multipart","unreachable"],"backgroundTag":"multipart-write-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"}