larksuite/cli · error

remove_attachment: failed to re-encode large attachment head

Error message

remove_attachment: failed to re-encode large attachment header: %w

What it means

Wraps json.Marshal failure when re-encoding the remaining large-attachment entries back into the CLI-format header after removal; the updated header could not be produced.

Source

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

		}
		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 {
		ID string `json:"id"`
	}, len(filtered))
	for i, it := range filtered {
		cliItems[i].ID = it.token()
	}
	encoded, err := json.Marshal(cliItems)
	if err != nil {
		return fmt.Errorf("remove_attachment: failed to re-encode large attachment header: %w", err)
	}
	snapshot.Headers[headerIdx].Name = LargeAttachmentIDsHeader
	snapshot.Headers[headerIdx].Value = base64.StdEncoding.EncodeToString(encoded)
	return nil
}

// removeTokenFromHTMLBody walks the HTML body, removes the single
// large-file-item whose anchor has data-mail-token == token, and if the
// enclosing container becomes empty (no more large-file-item children),
// removes the whole container.
//
// It is not an error if the HTML body or item is missing — the header
// removal is still considered the authoritative operation. This handles
// cases where the HTML was already edited out but the header wasn't.
func removeTokenFromHTMLBody(snapshot *DraftSnapshot, token string) error {
	htmlPart := FindHTMLBodyPart(snapshot.Body)
	if htmlPart == nil || len(htmlPart.Body) == 0 {
		return nil

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Report as a bug; token strings should always be JSON-encodable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at shortcuts/mail/draft/large_attachment_parse.go:314 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/81ebc1241d22ff37. Report an issue: GitHub.