siyuan-note/siyuan · error

createDocTree document list must not be empty

Error message

createDocTree document list must not be empty

What it means

After confirming the definition level is a list, parseNodes rejects an empty list. Every list in the createDocTree definition (top level and nested children) must contain at least one document dictionary; an empty children array at any level triggers this error.

Solutions

  1. Remove the empty "children" key from nodes without children; only include children when the list is non-empty.
  2. Add at least one document object to the top-level list.
  3. In generating code, omit children arrays of length 0 instead of serializing them.

Example fix

// before
[{"title": "Doc", "children": []}]
// after
[{"title": "Doc"}]
Defensive patterns

Strategy: validation

Validate before calling

function pruneEmptyChildren(nodes) {
  return nodes.map(n => {
    const out = { ...n };
    if (Array.isArray(out.children)) {
      if (out.children.length === 0) delete out.children;
      else out.children = pruneEmptyChildren(out.children);
    }
    return out;
  });
}

Prevention

When it happens

Trigger: Calling createDocTree with def = [] or with a node whose "children" key is set to [] instead of being omitted.

Common situations: UI form where the user cleared all rows; generator code that always emits a children key even when there are no children; template placeholders left unfilled.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree.go:130

		return nil, errors.New("createDocTree requires at least one document")
	}
	return nodes, nil
}

type templateDocTreeParseState struct {
	count int
}

func (state *templateDocTreeParseState) parseNodes(value any, depth int) ([]*TemplateDocTreeNode, error) {
	if maxTemplateDocTreeDepth < depth {
		return nil, fmt.Errorf("createDocTree exceeds the maximum depth of %d", maxTemplateDocTreeDepth)
	}
	values, ok := value.([]any)
	if !ok {
		return nil, errors.New("createDocTree definition must be a list")
	}
	if 0 == len(values) {
		return nil, errors.New("createDocTree document list must not be empty")
	}

	nodes := make([]*TemplateDocTreeNode, 0, len(values))
	for _, value := range values {
		definition, ok := value.(map[string]any)
		if !ok {
			return nil, errors.New("createDocTree document must be a dictionary")
		}
		for key := range definition {
			switch key {
			case "title", "template", "define", "children":
			default:
				return nil, fmt.Errorf("createDocTree document contains unknown field [%s]", key)
			}
		}

		titleValue, ok := definition["title"]
		if !ok {

View on GitHub (pinned to 9f775e8a12)