siyuan-note/siyuan · error

attribute view [ ] has no available view

Error message

attribute view [%s] has no available view: %w

What it means

When the template's attribute-view node specifies no view ID, validateTemplateAttributeViewNode falls back to attrView.GetFirstView(). If that also fails (the attribute view has no views at all), the underlying error is wrapped as 'attribute view [%s] has no available view'. Template rendering is aborted because there is nothing to render for the database block.

Solutions

  1. Open the attribute view in the SiYuan UI and add at least one view (e.g. a table view)
  2. Restore the database file from backup/sync history if views were lost to corruption
  3. Re-point the template's database block at a healthy attribute view
  4. Recreate the database and regenerate the template
Defensive patterns

Strategy: validation

Validate before calling

const av = await getAttrView(avID);
if (!av.views || av.views.length === 0) {
  await createAttrViewView(avID, "Table"); // ensure at least one view
}

Try / catch

try {
  await insertTemplate(path);
} catch (e) {
  if (String(e).includes("has no available view")) {
    await repairAttrViewViews(avID); // restore from backup or add a view
  }
}

Prevention

When it happens

Trigger: Rendering a template whose attribute-view node lacks `custom-av-view` while the referenced attribute view has zero views (e.g. a corrupted or manually truncated .av JSON where the Views array is empty), so GetFirstView errors and gets wrapped here.

Common situations: Databases damaged by partial writes, external edits to storage/av/*.json that emptied the views list, or templates copied from a source database that lost its views.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template.go:582

	if "" == value {
		return TemplateDatabaseModeCopy, nil
	}
	ret = TemplateDatabaseMode(value)
	if TemplateDatabaseModeCopy != ret && TemplateDatabaseModeReference != ret {
		return "", fmt.Errorf("unsupported template database mode [%s]", value)
	}
	return
}

func validateTemplateAttributeViewNode(node *ast.Node, attrView *av.AttributeView) (selectedView *av.View, err error) {
	viewID := strings.TrimSpace(node.IALAttr(av.NodeAttrView))
	if "" != viewID {
		selectedView = attrView.GetView(viewID)
		if nil == selectedView {
			return nil, fmt.Errorf("attribute view [%s] view [%s] not found", attrView.ID, viewID)
		}
	} else if selectedView, err = attrView.GetFirstView(); nil != err {
		return nil, fmt.Errorf("attribute view [%s] has no available view: %w", attrView.ID, err)
	}

	visibleViewIDs := strings.TrimSpace(node.IALAttr(av.NodeAttrVisibleViewIDs))
	if "" == visibleViewIDs {
		return
	}
	visibleViewCount := 0
	for _, visibleViewID := range strings.Split(visibleViewIDs, ",") {
		visibleViewID = strings.TrimSpace(visibleViewID)
		if "" == visibleViewID {
			continue
		}
		visibleViewCount++
		if nil == attrView.GetView(visibleViewID) {
			return nil, fmt.Errorf("attribute view [%s] visible view [%s] not found", attrView.ID, visibleViewID)
		}
	}
	if 1 > visibleViewCount {

View on GitHub (pinned to 9f775e8a12)