larksuite/cli · error

remove_attachment: token is empty

Error message

remove_attachment: token is empty

What it means

Guard in removeLargeAttachment: the remove_attachment op carries an empty token, so there is no attachment to identify and remove from the draft.

Source

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

	default:
		return 0
	}
	return int64(value * float64(mul))
}

// removeLargeAttachment removes a large attachment by its file token.
// It updates both representations:
//
//  1. X-Lms-Large-Attachment-Ids header: removes the token from the JSON
//     ID list. If the list becomes empty, the header itself is removed.
//  2. HTML body: removes the <div id="large-file-item"> whose <a> has the
//     matching data-mail-token attribute. If the enclosing container
//     <div id="large-file-area-*"> has no remaining items, the whole
//     container is removed.
func removeLargeAttachment(snapshot *DraftSnapshot, token string) error {
	token = strings.TrimSpace(token)
	if token == "" {
		return fmt.Errorf("remove_attachment: token is empty")
	}
	if err := removeTokenFromIDsHeader(snapshot, token); err != nil {
		return err
	}
	if err := removeTokenFromHTMLBody(snapshot, token); err != nil {
		return err
	}
	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 {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Pass the attachment's file token (from the draft's large-attachment header or list output)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at shortcuts/mail/draft/large_attachment_parse.go:259 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/59ddc17259fa1379. Report an issue: GitHub.