siyuan-note/siyuan · error

createDocTree document must be a dictionary

Error message

createDocTree document must be a dictionary

What it means

Each element of a createDocTree definition list must be a dictionary (map[string]any) describing one document. If an element is a string, number, or other non-object value, parseNodes returns this error before examining its fields.

Solutions

  1. Convert each list entry to an object with at least a title, e.g. {"title": "Chapter 1"}.
  2. If you only have title strings, map them: titles.map(t => ({title: t})).
  3. Verify nested children entries are also dictionaries, not strings.

Example fix

// before
{"def": ["Chapter 1", "Chapter 2"]}
// after
{"def": [{"title": "Chapter 1"}, {"title": "Chapter 2"}]}
Defensive patterns

Strategy: type-guard

Type guard

function isDocNodeList(list) {
  return Array.isArray(list) && list.every(n => typeof n === "object" && n !== null && !Array.isArray(n) && typeof n.title === "string");
}
if (!isDocNodeList(def)) throw new Error("every entry must be a document object with a title");

Try / catch

try {
  await createDocTree(payload);
} catch (e) {
  if (String(e).includes("must be a dictionary")) {
    // map string entries to {title: s} and retry once
  } else { throw e; }
}

Prevention

When it happens

Trigger: Passing definitions like ["Chapter 1"] (plain titles) or mixing objects and strings in the list; a children array containing scalars.

Common situations: Assuming the API accepts plain title strings; serializing a tree where leaves were stored as strings; hand-written JSON with a missing level of nesting.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/template_doc_tree.go:137

}

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 {
			return nil, errors.New("createDocTree document title is required")
		}
		title, ok := titleValue.(string)
		if !ok {
			return nil, errors.New("createDocTree document title must be a string")
		}
		title = normalizeDocTitle(title)

View on GitHub (pinned to 9f775e8a12)