larksuite/cli · error

remove_attachment: draft has no large attachment header

Error message

remove_attachment: draft has no large attachment header

What it means

Guard in removeTokenFromIDsHeader: the draft snapshot has no large-attachment ID header (either CLI or server format), so there is no large attachment registered to remove.

Source

Thrown at shortcuts/mail/draft/large_attachment_parse.go:284

	}
	return nil
}

// removeTokenFromIDsHeader removes the given token from whichever large
// attachment header is present (CLI or server format). Returns an error
// if no header is found or the token is not listed. After removal, the
// header is re-encoded in CLI format (X-Lms-Large-Attachment-Ids) so
// the server can process the update on upload.
func removeTokenFromIDsHeader(snapshot *DraftSnapshot, token string) error {
	headerIdx := -1
	for i, h := range snapshot.Headers {
		if IsLargeAttachmentHeader(h.Name) {
			headerIdx = i
			break
		}
	}
	if headerIdx < 0 {
		return fmt.Errorf("remove_attachment: draft has no large attachment header")
	}
	items, err := decodeLargeAttachmentHeader(snapshot.Headers[headerIdx].Value)
	if err != nil {
		return fmt.Errorf("remove_attachment: malformed large attachment header: %w", err)
	}
	filtered := make([]largeAttHeaderEntry, 0, len(items))
	removed := false
	for _, it := range items {
		if it.token() == token {
			removed = true
			continue
		}
		filtered = append(filtered, it)
	}
	if !removed {
		return fmt.Errorf("remove_attachment: token %q not found in large attachment header", token)
	}
	if len(filtered) == 0 {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Verify the draft actually has large attachments before calling remove_attachment
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at shortcuts/mail/draft/large_attachment_parse.go:284 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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