siyuan-note/siyuan · error

clone attribute view [%s] failed

Error message

clone attribute view [%s] failed

What it means

copyTemplateAttributeView clones a source attribute view (database) when rendering a template that embeds a database in copy mode. This error is thrown when av.AttributeView.Clone() returns nil despite the source being non-nil, meaning the clone could not be produced. It is a defensive internal invariant check guarding the copy pipeline before view ID remapping.

Source

Thrown at kernel/model/template.go:535

		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 8641553a1f)

Solutions

  1. Check that the source attribute view file (data/av/<id>.av or storage/av) exists, parses as JSON, and contains a valid ID matching the requested ID
  2. Re-open the database in the SiYuan UI to let the kernel re-index or rebuild the attribute view, then retry the template render
  3. If programmatically testing, ensure the source *av.AttributeView was produced by av.ParseAttributeView (not a zero-value struct) before calling copyTemplateAttributeView

Example fix

// before: passing a partially constructed attribute view
ret, err := copyTemplateAttributeView(&av.AttributeView{})
// after: parse the real attribute view first
src, err := av.ParseAttributeView(id)
if err != nil { return err }
ret, err := copyTemplateAttributeView(src)
Defensive patterns

Strategy: validation

Validate before calling

src, err := av.ParseAttributeView(id)
if err != nil || src == nil { return fmt.Errorf("attribute view %s unavailable", id) }
// then call copyTemplateAttributeView(src)

Type guard

if src == nil { return errors.New("nil attribute view") }

Try / catch

if ret, err := copyTemplateAttributeView(src); err != nil {
    logging.LogErrorf("copy av %s: %v", src.ID, err)
    return err
}

Prevention

When it happens

Trigger: A template containing a database node in TemplateDatabaseModeCopy is rendered and source.Clone() returns nil (Clone rejected the source, e.g. an empty or structurally invalid attribute view for the given ID).

Common situations: Rendering a template whose referenced attribute view file is corrupt, empty, or was written by an incompatible version so Clone yields nil; database .av JSON missing required fields.

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