siyuan-note/siyuan · error

clone attribute view

Error message

clone attribute view [%s] view failed

What it means

During the copy, each index i must yield both a non-nil source view and a non-nil cloned view; otherwise the copiedViewIDs mapping cannot be built. A nil entry aborts with 'clone attribute view [%s] view failed'. This guarantees the copy's view-ID remapping (source view ID -> cloned view ID) is complete before the cloned attribute view is used.

Solutions

  1. Open and re-save the source database in the UI to normalize its views
  2. Remove null view entries from the database's storage/av JSON (with a backup) or restore from history
  3. Update SiYuan if Clone behavior changed recently; report a reproducible case
  4. Recreate the database and regenerate the template
Defensive patterns

Strategy: validation

Validate before calling

const av = await getAttrView(avID);
if (av.views.some(v => v == null)) throw new Error("source attribute view contains null views");

Type guard

function hasNoNullViews(views: Array<View | null>): views is View[] {
  return views.every((v): v is View => v != null);
}

Try / catch

try {
  await insertTemplate(path);
} catch (e) {
  if (String(e).includes("view failed")) {
    await repairNullViews(avID); // remove null entries or restore from history
  }
}

Prevention

When it happens

Trigger: Copy-mode template rendering where source.Views or target.Views contains a nil element at some index despite matching lengths — usually a partially serialized view or a Clone bug producing nil placeholders.

Common situations: Corrupted attribute view JSON with null view entries, upstream av.Clone changes leaving nil slots, or templates referencing databases damaged by interrupted writes.

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/3ef44b9cc8bc6325. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template.go:627

			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 9f775e8a12)