larksuite/cli · error
inline cid is empty
Error message
inline cid is empty
What it means
validateCID enforces that a Content-ID for an inline part is non-empty before it is used in MIME headers and HTML references. An empty cid would produce an invalid Content-ID header and an unreferenceable <img src="cid:...">, so newInlinePart/replaceInline reject it up front.
Source
Thrown at shortcuts/mail/draft/patch.go:855
}
// normalizeCID strips a single RFC 2392 angle-bracket wrapper (<...>) from the
// CID if present, and trims surrounding whitespace. Unlike strings.Trim, it
// only removes a matched pair so that stray brackets like "test<>" are preserved
// for validation to reject.
func normalizeCID(cid string) string {
cid = strings.TrimSpace(cid)
if strings.HasPrefix(cid, "<") && strings.HasSuffix(cid, ">") {
cid = cid[1 : len(cid)-1]
}
return cid
}
// validateCID checks that a Content-ID value is non-empty and free of
// characters that would break MIME headers or cause ambiguous references.
func validateCID(cid string) error {
if cid == "" {
return fmt.Errorf("inline cid is empty")
}
if err := validate.RejectCRLF(cid, "inline cid"); err != nil {
return err
}
if strings.ContainsAny(cid, " \t<>()") {
return fmt.Errorf("inline cid %q contains invalid characters (spaces, tabs, angle brackets, or parentheses are not allowed)", cid)
}
return nil
}
func ensureInlineContainerRef(partRef **Part) (*Part, error) {
if partRef == nil || *partRef == nil {
return nil, fmt.Errorf("body container is nil")
}
part := *partRef
if strings.EqualFold(part.MediaType, "multipart/related") {
return part, nil
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Supply a non-empty cid, or omit cid and let generateCID create a UUID-based one
- Check your cid-producing code for empty results before building the op
- Generate the cid from the image path/UUID at call time rather than a blank template
Example fix
// before
{"op":"add_inline","target":{"cid":""},"path":"img.png"}
// after
{"op":"add_inline","target":{"cid":"a1b2c3d4-uuid"},"path":"img.png"} Defensive patterns
Strategy: validation
Validate before calling
func cidReady(cid string) bool {
return strings.TrimSpace(cid) != ""
}
// if empty, omit cid and let generateCID assign a UUID Type guard
func cidReady(cid string) bool {
return strings.TrimSpace(cid) != ""
} Try / catch
if err := applyOp(snap, op); err != nil && strings.Contains(err.Error(), "inline cid is empty") {
// regenerate a cid (UUID) and rebuild the op
} Prevention
- Check for empty cid before building the op; auto-generate one if absent
- Don't pass placeholders from templates unfilled
- Extract cids from source with a fallback to UUID generation
When it happens
Trigger: Calling inline-add/replace flows with cid:"" or whitespace that trims to empty; building the cid programmatically from a variable that was never set.
Common situations: Template-driven patch generation with unfilled placeholders; passing the filename instead of a generated cid by mistake; upstream cid extraction returning empty for images without a cid.
Related errors
- inline cid %q contains invalid characters (spaces, tabs, ang
- add_inline requires cid
- no part with cid %q found
- 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/342ebef90bc40edd.
Report an issue: GitHub.