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

  1. Set target.part_id or target.cid to a non-empty value from the current draft snapshot
  2. Fix the code path that builds the target so an identifier is always supplied
  3. 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

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


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