{"record":{"id":"77109c2ccaf6f1fa","repo":"larksuite/cli","slug":"target-must-specify-at-least-one-of-part-id-or-cid","errorCode":null,"errorMessage":"target must specify at least one of part_id or cid","messagePattern":"target must specify at least one of part_id or cid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":803,"sourceCode":"\t}\n\treturn false\n}\n\n// resolveTarget resolves an AttachmentTarget to a concrete part_id.\n// Priority: part_id > cid.\nfunc resolveTarget(snapshot *DraftSnapshot, target AttachmentTarget) (string, error) {\n\tif id := strings.TrimSpace(target.PartID); id != \"\" {\n\t\treturn id, nil\n\t}\n\tif cid := strings.TrimSpace(target.CID); cid != \"\" {\n\t\tcid = strings.Trim(cid, \"<>\")\n\t\tpart := findPartByCID(snapshot.Body, cid)\n\t\tif part == nil {\n\t\t\treturn \"\", fmt.Errorf(\"no part with cid %q found\", cid)\n\t\t}\n\t\treturn part.PartID, nil\n\t}\n\treturn \"\", fmt.Errorf(\"target must specify at least one of part_id or cid\")\n}\n\nfunc findPartByCID(root *Part, cid string) *Part {\n\tif root == nil {\n\t\treturn nil\n\t}\n\tif strings.EqualFold(strings.Trim(root.ContentID, \"<>\"), cid) {\n\t\treturn root\n\t}\n\tfor _, child := range root.Children {\n\t\tif found := findPartByCID(child, cid); found != nil {\n\t\t\treturn found\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc findPart(root *Part, partID string) *Part {","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L785-L821","documentation":"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.","triggerScenarios":"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\":\"\"}}.","commonSituations":"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.","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"],"exampleFix":"// before\n{\"op\":\"remove_inline\",\"target\":{}}\n// after\n{\"op\":\"remove_inline\",\"target\":{\"cid\":\"image001@domain\"}}","handlingStrategy":"validation","validationCode":"func targetHasKey(t Target) error {\n\tif strings.TrimSpace(t.PartID) == \"\" && strings.TrimSpace(t.CID) == \"\" {\n\t\treturn errors.New(\"target must specify part_id or cid\")\n\t}\n\treturn nil\n}","typeGuard":"func hasTargetKey(t Target) bool {\n\treturn strings.TrimSpace(t.PartID) != \"\" || strings.TrimSpace(t.CID) != \"\"\n}","tryCatchPattern":"if err := applyOp(snap, op); err != nil && strings.Contains(err.Error(), \"at least one of part_id or cid\") {\n\t// fix the op builder that produced an empty target\n}","preventionTips":["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"],"tags":["mail","draft","validation","missing-field"],"backgroundTag":"missing-required-argument","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"}