siyuan-note/siyuan · error

clone attribute view [%s] view failed

Error message

clone attribute view [%s] view failed

What it means

During per-view validation of a cloned attribute view, either the source view at index i or the corresponding cloned view is nil. The copy is aborted because the view cannot be remapped. This catches malformed individual views inside an otherwise size-matched Views slice.

Source

Thrown at kernel/model/template.go:543

			return view
		}
	}
	view, _ := attrView.GetFirstView()
	return view
}

func copyTemplateAttributeView(source *av.AttributeView) (ret *templateAttributeViewCopy, err error) {
	target := source.Clone()
	if nil == target {
		return nil, fmt.Errorf("clone attribute view [%s] failed", source.ID)
	}
	if len(source.Views) != len(target.Views) {
		return nil, fmt.Errorf("clone attribute view [%s] views failed", source.ID)
	}
	copiedViewIDs := map[string]string{}
	for i, sourceView := range source.Views {
		if nil == sourceView || nil == target.Views[i] {
			return nil, fmt.Errorf("clone attribute view [%s] view failed", source.ID)
		}
		copiedViewIDs[sourceView.ID] = target.Views[i].ID
	}
	return &templateAttributeViewCopy{target: target, copiedViewIDs: copiedViewIDs}, nil
}

func prepareTemplateAttributeViews(tree *parse.Tree, preview bool) (plans map[*ast.Node]*templateAttributeViewPlan,
	copies []*templateAttributeViewCopy, err error) {
	plans = map[*ast.Node]*templateAttributeViewPlan{}
	referenceSources := map[string]*av.AttributeView{}
	copySources := map[string]*av.AttributeView{}
	copyBySourceID := map[string]*templateAttributeViewCopy{}
	boxID := templateAttributeViewBoxID(tree)
	ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
		if !entering || ast.NodeAttributeView != n.Type {
			return ast.WalkContinue
		}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Remove null entries from the attribute view's Views array (fix the .av JSON or re-create the view in the UI)
  2. Rebuild/re-save the database so the kernel serializes a clean view list, then retry
  3. Ensure no code path inserts nil views into AttributeView.Views

Example fix

// before: .av JSON Views array containing null entries
// after: reopen and re-save the database in the UI, or strip nulls:
views := make([]*av.View, 0, len(src.Views))
for _, v := range src.Views { if v != nil { views = append(views, v) } }
src.Views = views
Defensive patterns

Strategy: validation

Validate before calling

for i, v := range src.Views { if v == nil { return fmt.Errorf("nil view at index %d", i) } }

Type guard

func hasNilView(src *av.AttributeView) bool {
    for _, v := range src.Views { if v == nil { return true } }
    return false
}

Try / catch

ret, err := copyTemplateAttributeView(src)
if err != nil { return fmt.Errorf("template database copy failed: %w", err) }

Prevention

When it happens

Trigger: Rendering a template with a copy-mode database where source.Views[i] is a nil entry or the clone produced a nil view at the same index.

Common situations: Hand-edited or partially written .av data containing null view entries; a clone bug that leaves holes in the slice.

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@8641553a1f (2026-09-11). Data as JSON: /api/errors/3ef44b9cc8bc6325. Report an issue: GitHub.