siyuan-note/siyuan · error
image data is empty
Error message
image data is empty
What it means
PrepareModelImage's first guard rejects nil/zero-length input before any detection. It means the caller passed an empty asset (failed download, zero-byte file, or nil pointer) to a multimodal model call.
Source
Thrown at kernel/util/openai.go:623
err = fmt.Errorf("rerank returned %d indices for %d documents", len(indices), len(documents))
return
}
seen := make(map[int]bool, len(indices))
for _, index := range indices {
if seen[index] {
err = fmt.Errorf("rerank returned duplicate index %d", index)
return
}
seen[index] = true
}
matched = true
return
}
// PrepareModelImage 校验并按需缩放图片,尽量保留多模态模型支持的原始格式和图片质量。
func PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {
if len(data) == 0 {
return PreparedImage{}, errors.New("image data is empty")
}
if maxBytes > 0 && len(data) > maxBytes {
return PreparedImage{}, fmt.Errorf("image exceeds size limit: %d bytes", maxBytes)
}
mimeType := mimetype.Detect(data).String()
if strings.Contains(mimeType, "svg") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte("<svg")) {
return PreparedImage{}, errors.New("SVG images are not accepted by multimodal models")
}
switch mimeType {
case "image/gif", "image/jpeg", "image/png", "image/webp":
default:
return PreparedImage{}, fmt.Errorf("unsupported image type: %s", mimeType)
}
config, _, err := image.DecodeConfig(bytes.NewReader(data))
if err != nil {
return PreparedImage{}, errors.New("unsupported or invalid image: " + err.Error())
}
if config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {View on GitHub (pinned to 251596fc0d)
Solutions
- Verify the source asset exists and is non-empty before calling.
- Check that the upstream download/read error is not being swallowed.
- Skip empty attachments instead of forwarding them to the model.
Example fix
// before
img, err := util.PrepareModelImage(maybeEmptyBytes, maxB, maxP, maxE)
// after
if len(raw) == 0 { return errors.New("no image content") }
img, err := util.PrepareModelImage(raw, maxB, maxP, maxE) Defensive patterns
Strategy: validation
Validate before calling
if len(data) == 0 { return errors.New("image is empty") }
img, err := util.PrepareModelImage(data, maxBytes, maxPixels, maxEdge) Type guard
func HasImageContent(data []byte) bool { return len(data) > 0 } Prevention
- Check len(data) before preparing
- Verify asset file size > 0 before reading
When it happens
Trigger: Calling a vision/multimodal model with a block whose image asset is missing or zero bytes; passing the result of a failed read/download that was swallowed.
Common situations: Asset path wrong so the read returns empty; network image download failed silently; PDF/image attachment not yet downloaded.
Related errors
- image exceeds size limit: %d bytes
- SVG images are not accepted by multimodal models
- unsupported image type: %s
- unsupported or invalid image:
- image exceeds pixel limit: %d
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/931951e2942c8885.
Report an issue: GitHub.