siyuan-note/siyuan · error

clone attribute view item

Error message

clone attribute view item [%s] failed

What it means

Inside CreateAttributeViewItemDocs, each detached item's av.Value is cloned before building the bound (attached) replacement value. av.Value.Clone() returning nil signals the clone failed or produced an unusable value; the function aborts that item with this wrapped error. It is a defensive check against an unexpected nil clone of an in-memory attribute-view row.

Solutions

  1. Reload the attribute view (close/reopen the database or restart the kernel) and retry CreateAttributeViewItemDocs; if it persists, inspect the item's row in the .av JSON for malformed block-value fields
  2. Exclude the offending itemID from the itemIDs list and convert remaining items; re-create the problematic row manually
  3. If caused by concurrent edits, retry after sync/idle so the .av file is stable
Defensive patterns

Strategy: try-catch

Validate before calling

if v := attrView.GetBlockValue(itemID); v == nil || v.Block == nil {
    return fmt.Errorf("item %s has unusable block value", itemID)
}

Type guard

func usableDetachedValue(v *av.Value) bool { return v != nil && v.IsDetached && v.Block != nil }

Try / catch

res, err := model.CreateAttributeViewItemDocs(avID, blockID, mode, itemIDs)
if err != nil && strings.Contains(err.Error(), "clone attribute view item") {
    // skip corrupt item and retry with remaining IDs
}

Prevention

When it happens

Trigger: CreateAttributeViewItemDocs is called with itemIDs whose row value passes the IsDetached/Block-non-nil filter, but value.Clone() unexpectedly returns nil (corrupt or malformed value data in the .av JSON, e.g. a Block value missing expected internals).

Common situations: Manually edited or partially synced attribute-view JSON files; items converted by an older version producing values the current Clone cannot represent; concurrent modification of the .av file while docs are being created.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/6de217357d0608f4. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/attribute_view_new_item.go:257

	var items []*itemDoc
	ret := &CreateAttributeViewItemDocsResult{}
	for _, itemID := range itemIDs {
		if "" == itemID || seen[itemID] {
			continue
		}
		seen[itemID] = true
		value := attrView.GetBlockValue(itemID)
		if nil == value || !value.IsDetached || nil == value.Block {
			ret.SkippedItemIDs = append(ret.SkippedItemIDs, itemID)
			continue
		}
		preview, resolveErr := resolveAttributeViewItemDocument(blockID, value.Block.Content, itemTemplate, createdAt)
		if nil != resolveErr {
			return nil, resolveErr
		}
		original := value.Clone()
		if nil == original {
			return nil, fmt.Errorf("clone attribute view item [%s] failed", itemID)
		}
		items = append(items, &itemDoc{itemID: itemID, original: original, preview: preview})
		ret.Warnings = append(ret.Warnings, preview.Warnings...)
	}
	if 0 == len(items) {
		return ret, nil
	}

	cleanupCreatedDocs := func() error {
		var cleanupErr error
		for i := len(items) - 1; 0 <= i; i-- {
			if "" != items[i].docID {
				cleanupErr = errors.Join(cleanupErr, removeCreatedNewItemDoc(items[i].docID))
			}
		}
		return cleanupErr
	}
	for _, item := range items {

View on GitHub (pinned to 9f775e8a12)