larksuite/cli · error

remove_inline: %w

Error message

remove_inline: %w

What it means

Wrapper around a resolveTarget failure during the 'remove_inline' op. The Target could not be resolved to an existing inline-image part in the snapshot; the concrete cause (missing part, wrong type, bad locator) is wrapped and preserved.

Source

Thrown at shortcuts/mail/draft/patch.go:133

			}
		}
		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)
	}
	return nil
}

func ensureHeaderEditable(name string, options PatchOptions) error {
	if protectedHeaders[strings.ToLower(strings.TrimSpace(name))] && !options.AllowProtectedHeaderEdits {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Read the wrapped cause (errors.Unwrap) to identify the resolution failure.
  2. Re-fetch a fresh DraftSnapshot before the removal.
  3. Locate the inline part by CID rather than guessing a partID.
  4. Skip the op if the part is already gone to make the patch idempotent.

Example fix

// before
ops := []PatchOp{{Op: "remove_inline", Target: Target{PartID: guessedID}}}
// after
snapshot := fetchFreshSnapshot(dctx)
if id, ok := findInlinePartByCID(snapshot, cid); ok {
    ops := []PatchOp{{Op: "remove_inline", Target: Target{PartID: id}}}
}
Defensive patterns

Strategy: validation

Validate before calling

func canRemoveInline(snap *DraftSnapshot, tgt Target) error {
    _, err := resolveTarget(snap, tgt)
    return err
} // call before building the op

Type guard

func inlinePartExists(snap *DraftSnapshot, tgt Target) bool {
    p, err := resolveTarget(snap, tgt)
    return err == nil && p != nil && p.ContentID != ""
}

Try / catch

if err := Apply(ctx, dctx, ops, opts); err != nil {
    if strings.HasPrefix(err.Error(), "remove_inline:") {
        return fmt.Errorf("inline part already gone or wrong type; refresh snapshot: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Apply with PatchOp{Op:"remove_inline"} whose Target is a nonexistent partID, already-removed part, or a part that is not an inline image.

Common situations: Removing inline images from a stale snapshot after prior patches; confusing attachment partIDs with inline partIDs; idempotent retry of an already-applied removal.

Related errors


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