{"record":{"id":"f5d771bd8d7f385f","repo":"larksuite/cli","slug":"s-header-is-empty","errorCode":null,"errorMessage":"%s header is empty","messagePattern":"(.+?) header is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":208,"sourceCode":"\tseen := false\n\tfor _, existing := range addrs {\n\t\tif strings.EqualFold(existing.Address, key) || strings.EqualFold(existing.Address, addr.Address) {\n\t\t\tseen = true\n\t\t\tbreak\n\t\t}\n\t}\n\tif !seen {\n\t\taddrs = append(addrs, addr)\n\t}\n\tsetRecipientField(snapshot, headerName, addrs)\n\treturn nil\n}\n\nfunc removeRecipient(snapshot *DraftSnapshot, field, address string) error {\n\tfield = strings.ToLower(strings.TrimSpace(field))\n\taddrs, headerName := recipientField(snapshot, field)\n\tif len(addrs) == 0 {\n\t\treturn fmt.Errorf(\"%s header is empty\", headerName)\n\t}\n\tneedle := strings.ToLower(strings.TrimSpace(address))\n\tnext := make([]Address, 0, len(addrs))\n\tremoved := false\n\tfor _, addr := range addrs {\n\t\tif strings.EqualFold(strings.TrimSpace(addr.Address), needle) {\n\t\t\tremoved = true\n\t\t\tcontinue\n\t\t}\n\t\tnext = append(next, addr)\n\t}\n\tif !removed {\n\t\treturn fmt.Errorf(\"recipient %q not found in %s\", address, headerName)\n\t}\n\tsetRecipientField(snapshot, headerName, next)\n\treturn nil\n}\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L190-L226","documentation":"removeRecipient refuses to remove from a to/cc/bcc header that currently has no recipients. This is a precondition check: the header list is empty, so there is nothing to remove and the requested remove_recipient op cannot succeed.","triggerScenarios":"A remove_recipient patch op (via applyOp) targeting a field (to/cc/bcc) that is empty in the draft snapshot — e.g. removing a recipient from Bcc when the draft has no Bcc entries.","commonSituations":"Script assumes a recipient exists (added in a prior step that failed or was skipped); removing from the wrong field (To vs Cc); operating on a freshly created draft that only has To populated.","solutions":["Check that the field has recipients before issuing remove_recipient","Verify you are targeting the correct field (to/cc/bcc) where the address actually lives","Make the removal idempotent: skip the op when the field is empty"],"exampleFix":"// before\napplyOp(op{Op: \"remove_recipient\", Field: \"bcc\", Address: addr}) // bcc may be empty\n// after\nif len(snap.Bcc) > 0 {\n    applyOp(op{Op: \"remove_recipient\", Field: \"bcc\", Address: addr})\n}","handlingStrategy":"validation","validationCode":"addrs, _ := recipientField(snap, field)\nif len(addrs) == 0 {\n    // skip remove_recipient; nothing to remove\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the draft's current recipients before issuing remove ops","Make removals idempotent: skip when the target field is empty","Double-check you target the field (to/cc/bcc) where the address actually is"],"tags":["precondition","email","draft-patch"],"backgroundTag":"empty-collection-operation","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"}