larksuite/cli · error
html body references missing inline cid %q
Error message
html body references missing inline cid %q
What it means
ValidateCIDReferences checks every cid: reference extracted from the HTML body against the set of available inline CID values (case-insensitively). If any referenced cid does not have a corresponding inline MIME part, the draft would render a broken image, so the library rejects it with this error. It is the post-processing gate after inline images are attached.
Source
Thrown at shortcuts/mail/draft/patch.go:1138
removeOrphanedInlineParts(child, referencedCIDs)
}
}
// ValidateCIDReferences checks that every cid: reference in the HTML body has
// a matching entry in availableCIDs. Returns an error for the first missing CID.
// Both sides are compared case-insensitively.
func ValidateCIDReferences(html string, availableCIDs []string) error {
refs := extractCIDRefs(html)
if len(refs) == 0 {
return nil
}
cidSet := make(map[string]bool, len(availableCIDs))
for _, cid := range availableCIDs {
cidSet[strings.ToLower(cid)] = true
}
for _, ref := range refs {
if !cidSet[strings.ToLower(ref)] {
return fmt.Errorf("html body references missing inline cid %q", ref)
}
}
return nil
}
// FindOrphanedCIDs returns CIDs from addedCIDs that are not referenced in the
// HTML body via <img src="cid:...">. These would appear as unexpected
// attachments when the email is sent.
func FindOrphanedCIDs(html string, addedCIDs []string) []string {
refs := extractCIDRefs(html)
refSet := make(map[string]bool, len(refs))
for _, ref := range refs {
refSet[strings.ToLower(ref)] = true
}
var orphaned []string
for _, cid := range addedCIDs {
if !refSet[strings.ToLower(cid)] {
orphaned = append(orphaned, cid)View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Re-run inline image resolution so every cid: in the HTML has a matching generated inline part
- Remove the stale cid: reference from the HTML body
- Ensure the image whose cid is referenced is still in the inline attachments list
- Check cid case matches (comparison is case-insensitive, but the part must exist)
Example fix
// before <img src="cid:old-pruned-cid@example"> // after <img src="cid:regenerated-cid-from-current-run@example"> // or drop the tag
Defensive patterns
Strategy: validation
Validate before calling
refs := extractCIDRefs(html)
for _, ref := range refs {
if !availableCIDSet[strings.ToLower(ref)] {
return fmt.Errorf("cid %q has no inline part; regenerate inline images", ref)
}
} Type guard
func allCIDsAvailable(html string, available []string) bool {
set := make(map[string]bool, len(available))
for _, c := range available { set[strings.ToLower(c)] = true }
for _, ref := range extractCIDRefs(html) {
if !set[strings.ToLower(ref)] { return false }
}
return true
} Try / catch
if err := postProcessInlineImages(snap, ...); err != nil {
if strings.Contains(err.Error(), "missing inline cid") {
return regenerateInlineImages(snap) // re-run resolution to rebuild cids
}
return err
} Prevention
- Never hand-edit cid: URLs in generated HTML
- Re-run inline image resolution after any body edit
- Keep inline parts and their cid references in the same patch pipeline
- Use FindOrphanedCIDs to detect drift before saving
When it happens
Trigger: Calling postProcessInlineImages when the HTML contains `cid:` references that are not in availableCIDs — e.g. a cid was pruned because its image file failed, the cid was generated for a different run, or the HTML was edited so the reference no longer matches any inline part.
Common situations: Hand-editing HTML and keeping an old cid: URL after the attachment was removed; patching a draft where a previous signature replacement dropped the inline part the body still references; case/whitespace mismatches that survive normalization.
Related errors
- add_inline requires cid
- add_inline requires path
- replace_inline requires target with at least one of part_id
- no part with cid %q found
- inline cid is empty
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/2111dcf4a331943a.
Report an issue: GitHub.