{"record":{"id":"81ebc1241d22ff37","repo":"larksuite/cli","slug":"remove-attachment-failed-to-re-encode-large-attac","errorCode":null,"errorMessage":"remove_attachment: failed to re-encode large attachment header: %w","messagePattern":"remove_attachment: failed to re-encode large attachment header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/large_attachment_parse.go","lineNumber":314,"sourceCode":"\t\t}\n\t\tfiltered = append(filtered, it)\n\t}\n\tif !removed {\n\t\treturn fmt.Errorf(\"remove_attachment: token %q not found in large attachment header\", token)\n\t}\n\tif len(filtered) == 0 {\n\t\tsnapshot.Headers = append(snapshot.Headers[:headerIdx], snapshot.Headers[headerIdx+1:]...)\n\t\treturn nil\n\t}\n\tcliItems := make([]struct {\n\t\tID string `json:\"id\"`\n\t}, len(filtered))\n\tfor i, it := range filtered {\n\t\tcliItems[i].ID = it.token()\n\t}\n\tencoded, err := json.Marshal(cliItems)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"remove_attachment: failed to re-encode large attachment header: %w\", err)\n\t}\n\tsnapshot.Headers[headerIdx].Name = LargeAttachmentIDsHeader\n\tsnapshot.Headers[headerIdx].Value = base64.StdEncoding.EncodeToString(encoded)\n\treturn nil\n}\n\n// removeTokenFromHTMLBody walks the HTML body, removes the single\n// large-file-item whose anchor has data-mail-token == token, and if the\n// enclosing container becomes empty (no more large-file-item children),\n// removes the whole container.\n//\n// It is not an error if the HTML body or item is missing — the header\n// removal is still considered the authoritative operation. This handles\n// cases where the HTML was already edited out but the header wasn't.\nfunc removeTokenFromHTMLBody(snapshot *DraftSnapshot, token string) error {\n\thtmlPart := FindHTMLBodyPart(snapshot.Body)\n\tif htmlPart == nil || len(htmlPart.Body) == 0 {\n\t\treturn nil","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/large_attachment_parse.go#L296-L332","documentation":"Wraps json.Marshal failure when re-encoding the remaining large-attachment entries back into the CLI-format header after removal; the updated header could not be produced.","triggerScenarios":"Thrown at shortcuts/mail/draft/large_attachment_parse.go:314 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Report as a bug; token strings should always be JSON-encodable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}