{"record":{"id":"16741b40e07863a1","repo":"larksuite/cli","slug":"replace-inline-w","errorCode":null,"errorMessage":"replace_inline: %w","messagePattern":"replace_inline: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":127,"sourceCode":"\t\t// the large attachment path (updates header + HTML card, no MIME\n\t\t// part to remove). Otherwise, resolve to a concrete part_id.\n\t\ttgt := op.Target\n\t\tif strings.TrimSpace(tgt.PartID) == \"\" && strings.TrimSpace(tgt.CID) == \"\" {\n\t\t\tif token := strings.TrimSpace(tgt.Token); token != \"\" {\n\t\t\t\treturn removeLargeAttachment(snapshot, token)\n\t\t\t}\n\t\t}\n\t\tpartID, err := resolveTarget(snapshot, tgt)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"remove_attachment: %w\", err)\n\t\t}\n\t\treturn removeAttachment(snapshot, partID)\n\tcase \"add_inline\":\n\t\treturn addInline(dctx, snapshot, op.Path, op.CID, op.FileName, op.ContentType)\n\tcase \"replace_inline\":\n\t\tpartID, err := resolveTarget(snapshot, op.Target)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"replace_inline: %w\", err)\n\t\t}\n\t\treturn replaceInline(dctx, snapshot, partID, op.Path, op.CID, op.FileName, op.ContentType)\n\tcase \"remove_inline\":\n\t\tpartID, err := resolveTarget(snapshot, op.Target)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"remove_inline: %w\", err)\n\t\t}\n\t\treturn removeInline(snapshot, partID)\n\tcase \"insert_signature\":\n\t\treturn insertSignatureOp(snapshot, op)\n\tcase \"remove_signature\":\n\t\treturn removeSignatureOp(snapshot)\n\tcase \"set_calendar\":\n\t\treturn applyCalendarSet(snapshot, op.CalendarICS)\n\tcase \"remove_calendar\":\n\t\treturn applyCalendarRemove(snapshot)\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported patch op %q\", op.Op)","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L109-L145","documentation":"Wrapper around a resolveTarget failure during the 'replace_inline' op. The op's Target could not be resolved to an existing inline-image part in the snapshot, so the replace cannot proceed; the underlying cause is wrapped.","triggerScenarios":"Calling Apply with PatchOp{Op:\"replace_inline\"} whose Target is a nonexistent/invalid partID or a target that does not identify an inline image (e.g. pointing at an attachment or a removed part).","commonSituations":"Replacing an inline image after the snapshot changed; using an attachment partID where a CID/inline partID is expected; repeated application of the same patch.","solutions":["Inspect the wrapped cause to see whether the part is missing or the wrong kind.","Re-fetch a fresh snapshot and re-resolve the inline part (find by CID) before patching.","Verify the target is an inline image part, not an attachment part.","Apply the patch only once and guard against double application."],"exampleFix":"// before\nop := PatchOp{Op: \"replace_inline\", Target: Target{PartID: someAttachmentID}}\n// after\ninlinePartID, err := findInlinePartIDByCID(snapshot, cid)\nif err != nil { return err }\nop := PatchOp{Op: \"replace_inline\", Target: Target{PartID: inlinePartID}}","handlingStrategy":"validation","validationCode":"func inlineTarget(snap *DraftSnapshot, cid string) (Target, error) {\n    id, err := findInlinePartIDByCID(snap, cid)\n    if err != nil { return Target{}, err }\n    return Target{PartID: id}, nil\n}","typeGuard":"func isInlineImage(snap *DraftSnapshot, tgt Target) bool {\n    p, err := resolveTarget(snap, tgt)\n    return err == nil && p != nil && strings.HasPrefix(p.ContentType, \"image/\") && p.ContentID != \"\"\n}","tryCatchPattern":"if err := Apply(ctx, dctx, ops, opts); err != nil {\n    if strings.HasPrefix(err.Error(), \"replace_inline:\") {\n        return fmt.Errorf(\"re-resolve inline part by CID before replacing: %w\", err)\n    }\n    return err\n}","preventionTips":["Resolve inline targets by Content-ID (CID), not by guessed partID.","Refetch the snapshot after any prior mutation before replacing.","Distinguish attachment parts from inline image parts when building targets.","Guard against applying the same patch twice."],"tags":["email","draft-patch","invalid-target"],"backgroundTag":"invalid-target-reference","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"}