siyuan-note/siyuan · error

clone attribute view

Error message

clone attribute view [%s] failed

What it means

copyTemplateAttributeView clones the source attribute view for template 'copy' mode via source.Clone(). If Clone returns nil — the av package signals an unrecoverable clone failure — this error is returned and template rendering stops. It surfaces internal clone failures rather than silently inserting an empty copy.

Solutions

  1. Open the source attribute view in the UI to confirm it loads and re-save it
  2. Restore the database file (storage/av/) from sync history or backup
  3. Recreate the database and regenerate the template
  4. Check for a recent SiYuan/av change affecting Clone and update or report the issue
Defensive patterns

Strategy: fallback

Validate before calling

const av = await getAttrView(avID);
if (!av || !av.views) throw new Error("source attribute view not loadable");

Try / catch

try {
  await insertTemplate(path);
} catch (e) {
  if (String(e).includes("clone attribute view")) {
    await restoreAttrViewFromHistory(avID); // then retry once
  }
}

Prevention

When it happens

Trigger: Rendering/inserting a template whose database block uses copy mode (the default) when av.AttributeView.Clone() returns nil, which happens when the clone cannot be constructed from the source attribute view's data.

Common situations: Corrupted or partially loaded attribute view data, a source database whose storage JSON cannot be materialized into a clonable structure, or an upstream av.Clone regression after version changes.

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

Appendix: source

Thrown at kernel/model/template.go:619

		return nil, fmt.Errorf("attribute view [%s] has no available visible view", attrView.ID)
	}
	return
}

func resolveCopyTemplateAttributeView(node *ast.Node, attrView *av.AttributeView) *av.View {
	if viewID := strings.TrimSpace(node.IALAttr(av.NodeAttrView)); "" != viewID {
		if view := attrView.GetView(viewID); nil != view {
			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{}

View on GitHub (pinned to 9f775e8a12)