larksuite/cli · error
replace_inline: %w
Error message
replace_inline: %w
What it means
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.
Source
Thrown at shortcuts/mail/draft/patch.go:127
// the large attachment path (updates header + HTML card, no MIME
// part to remove). Otherwise, resolve to a concrete part_id.
tgt := op.Target
if strings.TrimSpace(tgt.PartID) == "" && strings.TrimSpace(tgt.CID) == "" {
if token := strings.TrimSpace(tgt.Token); token != "" {
return removeLargeAttachment(snapshot, token)
}
}
partID, err := resolveTarget(snapshot, tgt)
if err != nil {
return fmt.Errorf("remove_attachment: %w", err)
}
return removeAttachment(snapshot, partID)
case "add_inline":
return addInline(dctx, snapshot, op.Path, op.CID, op.FileName, op.ContentType)
case "replace_inline":
partID, err := resolveTarget(snapshot, op.Target)
if err != nil {
return fmt.Errorf("replace_inline: %w", err)
}
return replaceInline(dctx, snapshot, partID, op.Path, op.CID, op.FileName, op.ContentType)
case "remove_inline":
partID, err := resolveTarget(snapshot, op.Target)
if err != nil {
return fmt.Errorf("remove_inline: %w", err)
}
return removeInline(snapshot, partID)
case "insert_signature":
return insertSignatureOp(snapshot, op)
case "remove_signature":
return removeSignatureOp(snapshot)
case "set_calendar":
return applyCalendarSet(snapshot, op.CalendarICS)
case "remove_calendar":
return applyCalendarRemove(snapshot)
default:
return fmt.Errorf("unsupported patch op %q", op.Op)View on GitHub (pinned to 7fd6ef3c07)
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.
Example fix
// before
op := PatchOp{Op: "replace_inline", Target: Target{PartID: someAttachmentID}}
// after
inlinePartID, err := findInlinePartIDByCID(snapshot, cid)
if err != nil { return err }
op := PatchOp{Op: "replace_inline", Target: Target{PartID: inlinePartID}} Defensive patterns
Strategy: validation
Validate before calling
func inlineTarget(snap *DraftSnapshot, cid string) (Target, error) {
id, err := findInlinePartIDByCID(snap, cid)
if err != nil { return Target{}, err }
return Target{PartID: id}, nil
} Type guard
func isInlineImage(snap *DraftSnapshot, tgt Target) bool {
p, err := resolveTarget(snap, tgt)
return err == nil && p != nil && strings.HasPrefix(p.ContentType, "image/") && p.ContentID != ""
} Try / catch
if err := Apply(ctx, dctx, ops, opts); err != nil {
if strings.HasPrefix(err.Error(), "replace_inline:") {
return fmt.Errorf("re-resolve inline part by CID before replacing: %w", err)
}
return err
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- remove_attachment: %w
- remove_inline: %w
- header %q is protected; rerun with allow_protected_header_ed
- recipient field must be one of to/cc/bcc
- recipient address is empty
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/16741b40e07863a1.
Report an issue: GitHub.