larksuite/cli · error
draft raw EML is empty
Error message
draft raw EML is empty
What it means
decodeRawEML validates the base64url-encoded EML string passed to Parse before decoding. This error means the caller supplied an empty (or whitespace-only) raw string, so there is nothing to decode into a draft EML document. The parser refuses early instead of producing a confusing downstream parse failure.
Source
Thrown at shortcuts/mail/draft/parse.go:49
snapshot := &DraftSnapshot{
DraftID: raw.DraftID,
Headers: headers,
Body: root,
}
if err := refreshSnapshot(snapshot); err != nil {
return nil, err
}
return snapshot, nil
}
// maxRawEMLSize is the maximum accepted raw (base64-encoded) EML string length.
// Base64 encodes 3 bytes into 4 chars, so 35 MB covers a 25 MB decoded EML with margin.
const maxRawEMLSize = 35 * 1024 * 1024
func decodeRawEML(raw string) ([]byte, error) {
raw = strings.TrimSpace(raw)
if raw == "" {
return nil, fmt.Errorf("draft raw EML is empty")
}
if len(raw) > maxRawEMLSize {
return nil, fmt.Errorf("draft raw EML is too large (%d bytes, max %d)", len(raw), maxRawEMLSize)
}
decoders := []func(string) ([]byte, error){
base64.URLEncoding.DecodeString,
base64.RawURLEncoding.DecodeString,
base64.StdEncoding.DecodeString,
base64.RawStdEncoding.DecodeString,
}
for _, decode := range decoders {
decoded, err := decode(raw)
if err == nil {
return normalizeLineEndings(decoded), nil
}
}
return nil, fmt.Errorf("draft raw EML is not valid base64url")
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Populate the raw string with the base64url-encoded EML from the mail API response before calling Parse
- Check the field you are passing is the raw EML (e.g. body.Raw or similar), not an unrelated empty string field
- Guard the call site: skip Parse or return a clearer error when the source draft has no raw content
Example fix
// before
part, err := draft.Parse(draft.Raw)
// after
if draft.Raw == "" {
return fmt.Errorf("draft %s has no raw EML to parse", draft.ID)
}
part, err := draft.Parse(draft.Raw) Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(rawEML) == "" {
return errors.New("no raw EML content: fetch the draft body before parsing")
} Try / catch
part, err := draft.Parse(rawEML)
if err != nil && strings.Contains(err.Error(), "draft raw EML is empty") {
// recover by re-fetching the draft raw content, then retry once
} Prevention
- Fetch raw EML content in the same code path that calls Parse
- Never pass optional/zero-valued string fields directly into Parse
- Trim inputs at the boundary so intent (empty vs whitespace) is explicit
When it happens
Trigger: Calling Parse with raw == "" or a string containing only whitespace (TrimSpace empties it); typically the draft's raw EML field was never fetched or a variable was left zero-valued.
Common situations: Fetching a draft whose body is empty/unsaved, forgetting to populate the raw EML field from a Lark mail API response before parsing, wiring the wrong struct field, or reading an empty file/env var into the raw string.
Related errors
- draft raw EML is too large (%d bytes, max %d)
- Invalid A1 range: {range_ref}
- skill reference is empty
- add_attachment requires path
- remove_attachment requires target with at least one of part_
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/be406d3a38844ab7.
Report an issue: GitHub.