siyuan-note/siyuan · error

renderDocRef children target must be a document ID

Error message

renderDocRef children target must be a document ID

What it means

In renderDocRef mode 'children', the query value must be the document ID (a Go string) whose children should be returned. If the template passes a non-string value (number, map, nil, etc.) the collector cannot look up the target node and throws this error before any tree traversal.

Solutions

  1. Pass the target document ID as a quoted string in the template action
  2. Verify the template expression feeding the value evaluates to a string
  3. Use mode "path" instead if you intend to target by path

Example fix

// before
{{renderDocRef "children" 12345}}
// after
{{renderDocRef "children" "20240101120000-abcdefg"}}
Defensive patterns

Strategy: validation

Validate before calling

if v, ok := value.(string); !ok || v == "" { return fmt.Errorf("children target must be a non-empty string ID") }

Type guard

func isDocID(v any) bool { s, ok := v.(string); return ok && len(s) > 0 }

Try / catch

out, err := collector.renderDocRef("children", value)
if err != nil && strings.Contains(err.Error(), "children target must be a document ID") {
  // coerce value to string or fix template arg
}

Prevention

When it happens

Trigger: A template's renderDocRef action with mode "children" receives a value that is not a string — e.g. an unquoted numeric ID, a parsed template expression yielding a non-string, or a missing/nil parameter binding.

Common situations: Template authors forgetting to quote the ID; template engines coercing IDs that look like numbers; passing a path instead of an ID to the children mode.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree.go:249

func (collector *templateDocTreeCollector) bindNodes(nodes []*TemplateDocTreeNode, parentID, parentPath, parentHPath string) {
	for _, node := range nodes {
		node.ParentID = parentID
		node.path = strings.TrimSuffix(parentPath, ".sy") + "/" + node.ID + ".sy"
		node.HPath = path.Join(parentHPath, node.Title)
		collector.bindNodes(node.Children, node.ID, node.path, node.HPath)
	}
}

func (collector *templateDocTreeCollector) renderDocRef(mode string, value any) (any, error) {
	if !collector.enabled {
		return nil, errors.New("renderDocRef is only available when manually inserting or previewing a template")
	}
	switch mode {
	case "children":
		id, ok := value.(string)
		if !ok {
			return nil, errors.New("renderDocRef children target must be a document ID")
		}
		if collector.rootID == id {
			return collector.nodes, nil
		}
		for _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {
			if node.ID == id {
				return node.Children, nil
			}
		}
		return []*TemplateDocTreeNode{}, nil
	case "path":
		hPath, ok := value.(string)
		if !ok {
			return "", errors.New("renderDocRef path target must be a document path")
		}
		requestedPath := path.Clean(hPath)
		for _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {
			relativePath := strings.TrimPrefix(node.HPath, collector.rootHPath)

View on GitHub (pinned to 9f775e8a12)