larksuite/cli · error

remove_attachment: malformed large attachment header: %w

Error message

remove_attachment: malformed large attachment header: %w

What it means

Wraps decodeLargeAttachmentHeader failure: the draft's large-attachment ID header exists but its JSON payload is malformed, so the token list cannot be parsed for removal.

Source

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

// 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 {
		snapshot.Headers = append(snapshot.Headers[:headerIdx], snapshot.Headers[headerIdx+1:]...)
		return nil
	}
	cliItems := make([]struct {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Fix or regenerate the draft's large-attachment header; re-fetch the draft if server-side state diverged
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class


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