larksuite/cli · error

%s header is empty

Error message

%s header is empty

What it means

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.

Source

Thrown at shortcuts/mail/draft/patch.go:208

	seen := false
	for _, existing := range addrs {
		if strings.EqualFold(existing.Address, key) || strings.EqualFold(existing.Address, addr.Address) {
			seen = true
			break
		}
	}
	if !seen {
		addrs = append(addrs, addr)
	}
	setRecipientField(snapshot, headerName, addrs)
	return nil
}

func removeRecipient(snapshot *DraftSnapshot, field, address string) error {
	field = strings.ToLower(strings.TrimSpace(field))
	addrs, headerName := recipientField(snapshot, field)
	if len(addrs) == 0 {
		return fmt.Errorf("%s header is empty", headerName)
	}
	needle := strings.ToLower(strings.TrimSpace(address))
	next := make([]Address, 0, len(addrs))
	removed := false
	for _, addr := range addrs {
		if strings.EqualFold(strings.TrimSpace(addr.Address), needle) {
			removed = true
			continue
		}
		next = append(next, addr)
	}
	if !removed {
		return fmt.Errorf("recipient %q not found in %s", address, headerName)
	}
	setRecipientField(snapshot, headerName, next)
	return nil
}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Check that the field has recipients before issuing remove_recipient
  2. Verify you are targeting the correct field (to/cc/bcc) where the address actually lives
  3. Make the removal idempotent: skip the op when the field is empty

Example fix

// before
applyOp(op{Op: "remove_recipient", Field: "bcc", Address: addr}) // bcc may be empty
// after
if len(snap.Bcc) > 0 {
    applyOp(op{Op: "remove_recipient", Field: "bcc", Address: addr})
}
Defensive patterns

Strategy: validation

Validate before calling

addrs, _ := recipientField(snap, field)
if len(addrs) == 0 {
    // skip remove_recipient; nothing to remove
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/f5d771bd8d7f385f. Report an issue: GitHub.