{"record":{"id":"7ae970ecdeb8b959","repo":"larksuite/cli","slug":"recipient-q-not-found-in-s","errorCode":null,"errorMessage":"recipient %q not found in %s","messagePattern":"recipient %q not found in (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":221,"sourceCode":"\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\nfunc recipientField(snapshot *DraftSnapshot, field string) ([]Address, string) {\n\tswitch field {\n\tcase \"to\":\n\t\treturn append([]Address{}, snapshot.To...), \"To\"\n\tcase \"cc\":\n\t\treturn append([]Address{}, snapshot.Cc...), \"Cc\"\n\tcase \"bcc\":\n\t\treturn append([]Address{}, snapshot.Bcc...), \"Bcc\"\n\tdefault:\n\t\treturn nil, \"\"\n\t}\n}\n","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L203-L239","documentation":"removeRecipient compares the requested address (case-insensitively, trimmed) against every recipient in the target field. If none matches, the header is left untouched and this error names the address and the header (To/Cc/Bcc) it was not found in.","triggerScenarios":"A remove_recipient patch op (via applyOp) with an address string that differs from what is stored — wrong case is fine (EqualFold), but extra display-name text, different whitespace, an alias, or a wrong field will not match.","commonSituations":"Passing 'Bob <bob@x.com>' when only 'bob@x.com' is stored; removing from Cc when the address is in To; the recipient was already removed by a previous op; typo or outdated address from a cached list.","solutions":["Pass the bare email address exactly as stored, not the 'Name <addr>' form","Read the draft's current recipients first and confirm the address and field before removing","Handle the already-removed case as success if removal is idempotent in your workflow"],"exampleFix":"// before\nremoveRecipient(snap, \"cc\", \"Bob <bob@x.com>\")\n// after\nremoveRecipient(snap, \"cc\", \"bob@x.com\") // bare stored address, case-insensitive","handlingStrategy":"validation","validationCode":"needle := strings.ToLower(strings.TrimSpace(address))\nfound := false\nfor _, a := range snap.Cc {\n    if strings.EqualFold(strings.TrimSpace(a.Address), needle) {\n        found = true\n        break\n    }\n}\nif !found { /* skip or report */ }","typeGuard":null,"tryCatchPattern":"if err := applyOp(op); err != nil && strings.Contains(err.Error(), \"not found in\") {\n    // treat as already-removed, continue\n}","preventionTips":["Pass the bare stored email, never the 'Name <addr>' display form","Fetch the draft and confirm membership before removing","Handle repeat removals gracefully in scripts"],"tags":["email","not-found","draft-patch"],"backgroundTag":"value-not-found","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"}