larksuite/cli · error
target must specify at least one of part_id or cid
Error message
target must specify at least one of part_id or cid
What it means
resolveTarget requires the target of an inline patch operation to identify a part via at least one key: part_id or cid. When both are empty/absent, there is nothing to resolve, so it fails with this error. This is an input-validation error, not a lookup failure.
Source
Thrown at shortcuts/mail/draft/patch.go:803
}
return false
}
// resolveTarget resolves an AttachmentTarget to a concrete part_id.
// Priority: part_id > cid.
func resolveTarget(snapshot *DraftSnapshot, target AttachmentTarget) (string, error) {
if id := strings.TrimSpace(target.PartID); id != "" {
return id, nil
}
if cid := strings.TrimSpace(target.CID); cid != "" {
cid = strings.Trim(cid, "<>")
part := findPartByCID(snapshot.Body, cid)
if part == nil {
return "", fmt.Errorf("no part with cid %q found", cid)
}
return part.PartID, nil
}
return "", fmt.Errorf("target must specify at least one of part_id or cid")
}
func findPartByCID(root *Part, cid string) *Part {
if root == nil {
return nil
}
if strings.EqualFold(strings.Trim(root.ContentID, "<>"), cid) {
return root
}
for _, child := range root.Children {
if found := findPartByCID(child, cid); found != nil {
return found
}
}
return nil
}
func findPart(root *Part, partID string) *Part {View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Set target.part_id or target.cid to a non-empty value from the current draft snapshot
- Fix the code path that builds the target so an identifier is always supplied
- Fail fast in your patch builder if both identifiers are blank
Example fix
// before
{"op":"remove_inline","target":{}}
// after
{"op":"remove_inline","target":{"cid":"image001@domain"}} Defensive patterns
Strategy: validation
Validate before calling
func targetHasKey(t Target) error {
if strings.TrimSpace(t.PartID) == "" && strings.TrimSpace(t.CID) == "" {
return errors.New("target must specify part_id or cid")
}
return nil
} Type guard
func hasTargetKey(t Target) bool {
return strings.TrimSpace(t.PartID) != "" || strings.TrimSpace(t.CID) != ""
} Try / catch
if err := applyOp(snap, op); err != nil && strings.Contains(err.Error(), "at least one of part_id or cid") {
// fix the op builder that produced an empty target
} Prevention
- Validate patch ops before submission: every inline target needs part_id or cid
- Fail fast in your op-builder when the identifier variable is empty
- Don't serialize empty-string fields that drop out and leave {} targets
When it happens
Trigger: Submitting an inline op whose target object is {} or has only empty strings for part_id and cid, e.g. {"target":{}} or {"target":{"part_id":""}}.
Common situations: Programmatically building patch ops where the identifier variable was never populated; JSON serialization dropping empty fields; copying an op template without filling in the target.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- add_attachment requires path
- remove_attachment requires target with at least one of part_
- add_inline requires path
- add_inline requires cid
- replace_inline requires target with at least one of part_id
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/77109c2ccaf6f1fa.
Report an issue: GitHub.