{"record":{"id":"99b51aa37a3f5001","repo":"larksuite/cli","slug":"recipient-address-is-empty","errorCode":null,"errorMessage":"recipient address is empty","messagePattern":"recipient address is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":166,"sourceCode":"}\n\nfunc ensureHeaderEditable(name string, options PatchOptions) error {\n\tif protectedHeaders[strings.ToLower(strings.TrimSpace(name))] && !options.AllowProtectedHeaderEdits {\n\t\treturn fmt.Errorf(\"header %q is protected; rerun with allow_protected_header_edits\", name)\n\t}\n\treturn nil\n}\n\nfunc setRecipients(snapshot *DraftSnapshot, field string, addrs []Address) error {\n\tfield = strings.ToLower(strings.TrimSpace(field))\n\tif !isRecipientField(field) {\n\t\treturn fmt.Errorf(\"recipient field must be one of to/cc/bcc\")\n\t}\n\tnormalized := make([]Address, 0, len(addrs))\n\tseen := map[string]bool{}\n\tfor _, addr := range addrs {\n\t\tif strings.TrimSpace(addr.Address) == \"\" {\n\t\t\treturn fmt.Errorf(\"recipient address is empty\")\n\t\t}\n\t\tkey := strings.ToLower(strings.TrimSpace(addr.Address))\n\t\tif seen[key] {\n\t\t\tcontinue\n\t\t}\n\t\tseen[key] = true\n\t\tnormalized = append(normalized, Address{\n\t\t\tName:    addr.Name,\n\t\t\tAddress: strings.TrimSpace(addr.Address),\n\t\t})\n\t}\n\t_, headerName := recipientField(snapshot, field)\n\tsetRecipientField(snapshot, headerName, normalized)\n\treturn nil\n}\n\nfunc addRecipient(snapshot *DraftSnapshot, field string, addr Address) error {\n\tif strings.TrimSpace(addr.Address) == \"\" {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L148-L184","documentation":"setRecipients validates every Address in the list being assigned to a to/cc/bcc field. If any entry has an Address value that is empty or whitespace-only, the entire patch op is rejected because a header entry without an address cannot be serialized. Note the operation is all-or-nothing: one bad entry blocks the whole set.","triggerScenarios":"Calling set_recipients (via applyOp) or buildDraftEditPatch with an Address whose Address field is \"\" or only spaces, e.g. parsing \"Name <\" or splitting an address list that ends with a separator.","commonSituations":"Building recipient lists from user input or CSV rows where a trailing comma or blank row yields an empty address; programmatic name-only entries (Name set, Address empty); template placeholders never filled in.","solutions":["Filter out entries with empty/whitespace Address values before calling set_recipients","Parse display-name-style input so Address is extracted (e.g. 'Bob <bob@x.com>' -> bob@x.com) instead of storing only the name","If the whole field should be cleared, pass an empty list rather than a list containing a blank address"],"exampleFix":"// before\nsetRecipients(snap, \"to\", []Address{{Name: \"Bob\", Address: \"\"}})\n// after\naddrs := []Address{{Name: \"Bob\", Address: \"\"}}\nvar valid []Address\nfor _, a := range addrs {\n    if strings.TrimSpace(a.Address) != \"\" {\n        valid = append(valid, a)\n    }\n}\nsetRecipients(snap, \"to\", valid)","handlingStrategy":"validation","validationCode":"func validRecipients(addrs []Address) bool {\n    for _, a := range addrs {\n        if strings.TrimSpace(a.Address) == \"\" {\n            return false\n        }\n    }\n    return true\n}","typeGuard":"func hasAddress(a Address) bool { return strings.TrimSpace(a.Address) != \"\" }","tryCatchPattern":null,"preventionTips":["Filter blank entries from recipient lists before building patch ops","Parse 'Name <addr>' strings so Address is always populated","Treat an empty field as an empty list, never a list with one blank entry"],"tags":["validation","email","draft-patch"],"backgroundTag":"empty-required-field","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"}