{"record":{"id":"ba16157edb16f11f","repo":"larksuite/cli","slug":"remove-attachment-malformed-large-attachment-head","errorCode":null,"errorMessage":"remove_attachment: malformed large attachment header: %w","messagePattern":"remove_attachment: malformed large attachment header: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/large_attachment_parse.go","lineNumber":288,"sourceCode":"// removeTokenFromIDsHeader removes the given token from whichever large\n// attachment header is present (CLI or server format). Returns an error\n// if no header is found or the token is not listed. After removal, the\n// header is re-encoded in CLI format (X-Lms-Large-Attachment-Ids) so\n// the server can process the update on upload.\nfunc removeTokenFromIDsHeader(snapshot *DraftSnapshot, token string) error {\n\theaderIdx := -1\n\tfor i, h := range snapshot.Headers {\n\t\tif IsLargeAttachmentHeader(h.Name) {\n\t\t\theaderIdx = i\n\t\t\tbreak\n\t\t}\n\t}\n\tif headerIdx < 0 {\n\t\treturn fmt.Errorf(\"remove_attachment: draft has no large attachment header\")\n\t}\n\titems, err := decodeLargeAttachmentHeader(snapshot.Headers[headerIdx].Value)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"remove_attachment: malformed large attachment header: %w\", err)\n\t}\n\tfiltered := make([]largeAttHeaderEntry, 0, len(items))\n\tremoved := false\n\tfor _, it := range items {\n\t\tif it.token() == token {\n\t\t\tremoved = true\n\t\t\tcontinue\n\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 {","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/large_attachment_parse.go#L270-L306","documentation":"Wraps decodeLargeAttachmentHeader failure: the draft's large-attachment ID header exists but its JSON payload is malformed, so the token list cannot be parsed for removal.","triggerScenarios":"Thrown at shortcuts/mail/draft/large_attachment_parse.go:288 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix or regenerate the draft's large-attachment header; re-fetch the draft if server-side state diverged"],"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"}