{"record":{"id":"1bf851c690142951","repo":"larksuite/cli","slug":"replace-inline-requires-target-with-at-least-one-o","errorCode":null,"errorMessage":"replace_inline requires target with at least one of part_id or cid","messagePattern":"replace_inline requires target with at least one of part_id or cid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/model.go","lineNumber":331,"sourceCode":"\t\t}\n\tcase \"add_attachment\":\n\t\tif strings.TrimSpace(op.Path) == \"\" {\n\t\t\treturn fmt.Errorf(\"add_attachment requires path\")\n\t\t}\n\tcase \"remove_attachment\":\n\t\tif !op.Target.hasAnyKey() {\n\t\t\treturn fmt.Errorf(\"remove_attachment requires target with at least one of part_id, cid, or token\")\n\t\t}\n\tcase \"add_inline\":\n\t\tif strings.TrimSpace(op.Path) == \"\" {\n\t\t\treturn fmt.Errorf(\"add_inline requires path\")\n\t\t}\n\t\tif strings.TrimSpace(op.CID) == \"\" {\n\t\t\treturn fmt.Errorf(\"add_inline requires cid\")\n\t\t}\n\tcase \"replace_inline\":\n\t\tif !op.Target.hasKey() {\n\t\t\treturn fmt.Errorf(\"replace_inline requires target with at least one of part_id or cid\")\n\t\t}\n\t\tif strings.TrimSpace(op.Path) == \"\" {\n\t\t\treturn fmt.Errorf(\"replace_inline requires path\")\n\t\t}\n\tcase \"remove_inline\":\n\t\tif !op.Target.hasKey() {\n\t\t\treturn fmt.Errorf(\"remove_inline requires target with at least one of part_id or cid\")\n\t\t}\n\tcase \"insert_signature\":\n\t\tif strings.TrimSpace(op.SignatureID) == \"\" {\n\t\t\treturn fmt.Errorf(\"insert_signature requires signature_id\")\n\t\t}\n\tcase \"remove_signature\":\n\t\t// No required fields.\n\tcase \"set_calendar\":\n\t\tif strings.TrimSpace(op.EventSummary) == \"\" {\n\t\t\treturn fmt.Errorf(\"set_calendar requires event_summary\")\n\t\t}","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/model.go#L313-L349","documentation":"A `replace_inline` operation swaps the content of an existing inline resource, so it must first identify that resource via `part_id` or `cid` in its `target` object. If the target lacks both keys, the validator rejects the op because it cannot determine which inline resource to replace.","triggerScenarios":"Submitting `{\"op\":\"replace_inline\",\"path\":\"/tmp/new.png\"}` with no `target`, `target: {}`, or a target containing only keys other than part_id/cid (e.g. token, which remove_attachment accepts but replace_inline does not — hasKey() checks only part_id and cid).","commonSituations":"Replacing an inline image without first reading the draft to get its part_id or cid; reusing a remove_attachment-style target that used token; target JSON nested at the wrong level.","solutions":["Add `part_id` or `cid` to the operation's `target` object identifying the inline resource to replace","Fetch the current draft to obtain the existing inline resource's part_id or cid before replacing","Ensure `path` is also set, since replace_inline additionally requires the replacement file"],"exampleFix":"// before\n{\"op\":\"replace_inline\",\"path\":\"/tmp/new-logo.png\"}\n// after\n{\"op\":\"replace_inline\",\"target\":{\"cid\":\"logo1\"},\"path\":\"/tmp/new-logo.png\"}","handlingStrategy":"validation","validationCode":"if !op.Target.hasKey() {\n    return fmt.Errorf(\"replace_inline requires target with at least one of part_id or cid\")\n}","typeGuard":"func inlineTargetIdentified(t Target) bool { return t.hasKey() }","tryCatchPattern":null,"preventionTips":["Fetch the draft to get part_id or cid before replacing an inline resource","Note replace_inline accepts only part_id or cid, not token","Always pair the target with a non-empty path for the replacement file"],"tags":["validation","mail","draft","inline-image","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"}