siyuan-note/siyuan · error
invalid rich clipboard asset count
Error message
invalid rich clipboard asset count [%d]
What it means
PrepareRichClipboardAssets (kernel/model/clipboard.go:68) validates that a rich-clipboard copy carries a non-empty batch of at most 1024 assets; otherwise it returns fmt.Errorf("invalid rich clipboard asset count [%d]", len(assets)). The guard `len(assets) < 1 || 1024 < len(assets)` rejects both empty payloads and oversized ones before any filesystem work starts. On failure the prepared batch is discarded via the deferred cleanupRichClipboardGroups.
Solutions
- Check the caller: skip the kernel call entirely when the collected asset list is empty and show a normal (non-rich) paste path
- Chunk or deduplicate the asset list to stay at or below 1024 entries before calling PrepareRichClipboardAssets
- Log the actual count from the error message and inspect why so many entries were collected (dedupe by asset path)
- Treat the returned error as a caller-input validation failure; no retry will help
Example fix
// before
prepared, err := model.PrepareRichClipboardAssets(allAssets) // may be 5000 entries
// after
if len(allAssets) == 0 || len(allAssets) > 1024 {
return fmt.Errorf("rich clipboard payload must contain 1..1024 assets, got %d", len(allAssets))
}
prepared, err := model.PrepareRichClipboardAssets(allAssets) Defensive patterns
Strategy: validation
Validate before calling
if len(assets) < 1 || len(assets) > 1024 {
return fmt.Errorf("asset count %d out of range 1..1024", len(assets))
} Prevention
- Skip the rich-clipboard path when no image assets were collected
- Deduplicate and chunk large asset lists to stay within the 1024 cap
- Never retry on this error — it is a deterministic input validation failure
When it happens
Trigger: Calling PrepareRichClipboardAssets with an empty slice (nothing copied) or with more than 1024 RichClipboardAsset entries — e.g. pasting a document containing thousands of images in one operation.
Common situations: Frontend submitting an empty assets array when the clipboard parse found no images; batch-pasting very large HTML/exports with >1024 image references; a loop bug that duplicates entries past the cap.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- createDocTree exceeds the maximum depth of
- Field [assets. .box] should be of type [String]
- Field [assets. ] should be of type [Object]
- Field [assets] must not be empty
- Field [batch] must not be empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/74e4fc437d2023e4.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/clipboard.go:68
Index int
Path string
Box string
}
type RichClipboardPreparedAsset struct {
Index int `json:"index"`
Path string `json:"path"`
}
type RichClipboardPrepared struct {
Batch string `json:"batch"`
Groups []string `json:"groups"`
Assets []RichClipboardPreparedAsset `json:"assets"`
}
func PrepareRichClipboardAssets(assets []RichClipboardAsset) (ret *RichClipboardPrepared, err error) {
if len(assets) < 1 || 1024 < len(assets) {
return nil, fmt.Errorf("invalid rich clipboard asset count [%d]", len(assets))
}
batch := util.RandString(24)
groups := map[string]struct{}{}
copied := map[string]string{}
ret = &RichClipboardPrepared{Batch: batch}
defer func() {
if err != nil {
cleanupRichClipboardGroups(batch, groups)
}
}()
for _, asset := range assets {
if asset.Index < 0 {
return nil, fmt.Errorf("invalid rich clipboard asset index [%d]", asset.Index)
}
ext := strings.ToLower(filepath.Ext(AssetPathWithoutQuery(asset.Path)))View on GitHub (pinned to 9f775e8a12)