{"record":{"id":"59ddc17259fa1379","repo":"larksuite/cli","slug":"remove-attachment-token-is-empty","errorCode":null,"errorMessage":"remove_attachment: token is empty","messagePattern":"remove_attachment: token is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/large_attachment_parse.go","lineNumber":259,"sourceCode":"\tdefault:\n\t\treturn 0\n\t}\n\treturn int64(value * float64(mul))\n}\n\n// removeLargeAttachment removes a large attachment by its file token.\n// It updates both representations:\n//\n//  1. X-Lms-Large-Attachment-Ids header: removes the token from the JSON\n//     ID list. If the list becomes empty, the header itself is removed.\n//  2. HTML body: removes the <div id=\"large-file-item\"> whose <a> has the\n//     matching data-mail-token attribute. If the enclosing container\n//     <div id=\"large-file-area-*\"> has no remaining items, the whole\n//     container is removed.\nfunc removeLargeAttachment(snapshot *DraftSnapshot, token string) error {\n\ttoken = strings.TrimSpace(token)\n\tif token == \"\" {\n\t\treturn fmt.Errorf(\"remove_attachment: token is empty\")\n\t}\n\tif err := removeTokenFromIDsHeader(snapshot, token); err != nil {\n\t\treturn err\n\t}\n\tif err := removeTokenFromHTMLBody(snapshot, token); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\n// 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 {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/large_attachment_parse.go#L241-L277","documentation":"Guard in removeLargeAttachment: the remove_attachment op carries an empty token, so there is no attachment to identify and remove from the draft.","triggerScenarios":"Thrown at shortcuts/mail/draft/large_attachment_parse.go:259 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the attachment's file token (from the draft's large-attachment header or list output)"],"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"}