{"record":{"id":"74e4fc437d2023e4","repo":"siyuan-note/siyuan","slug":"invalid-rich-clipboard-asset-count-d","errorCode":null,"errorMessage":"invalid rich clipboard asset count [%d]","messagePattern":"invalid rich clipboard asset count \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/clipboard.go","lineNumber":68,"sourceCode":"\tIndex int\n\tPath  string\n\tBox   string\n}\n\ntype RichClipboardPreparedAsset struct {\n\tIndex int    `json:\"index\"`\n\tPath  string `json:\"path\"`\n}\n\ntype RichClipboardPrepared struct {\n\tBatch  string                       `json:\"batch\"`\n\tGroups []string                     `json:\"groups\"`\n\tAssets []RichClipboardPreparedAsset `json:\"assets\"`\n}\n\nfunc PrepareRichClipboardAssets(assets []RichClipboardAsset) (ret *RichClipboardPrepared, err error) {\n\tif len(assets) < 1 || 1024 < len(assets) {\n\t\treturn nil, fmt.Errorf(\"invalid rich clipboard asset count [%d]\", len(assets))\n\t}\n\n\tbatch := util.RandString(24)\n\tgroups := map[string]struct{}{}\n\tcopied := map[string]string{}\n\tret = &RichClipboardPrepared{Batch: batch}\n\tdefer func() {\n\t\tif err != nil {\n\t\t\tcleanupRichClipboardGroups(batch, groups)\n\t\t}\n\t}()\n\n\tfor _, asset := range assets {\n\t\tif asset.Index < 0 {\n\t\t\treturn nil, fmt.Errorf(\"invalid rich clipboard asset index [%d]\", asset.Index)\n\t\t}\n\n\t\text := strings.ToLower(filepath.Ext(AssetPathWithoutQuery(asset.Path)))","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/clipboard.go#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nprepared, err := model.PrepareRichClipboardAssets(allAssets) // may be 5000 entries\n\n// after\nif len(allAssets) == 0 || len(allAssets) > 1024 {\n    return fmt.Errorf(\"rich clipboard payload must contain 1..1024 assets, got %d\", len(allAssets))\n}\nprepared, err := model.PrepareRichClipboardAssets(allAssets)","handlingStrategy":"validation","validationCode":"if len(assets) < 1 || len(assets) > 1024 {\n    return fmt.Errorf(\"asset count %d out of range 1..1024\", len(assets))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["clipboard","validation","limit-exceeded"],"backgroundTag":"value-out-of-range","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}