{"record":{"id":"5396663c74ace686","repo":"siyuan-note/siyuan","slug":"createdoctree-document-must-be-a-dictionary","errorCode":null,"errorMessage":"createDocTree document must be a dictionary","messagePattern":"createDocTree document must be a dictionary","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":137,"sourceCode":"}\n\nfunc (state *templateDocTreeParseState) parseNodes(value any, depth int) ([]*TemplateDocTreeNode, error) {\n\tif maxTemplateDocTreeDepth < depth {\n\t\treturn nil, fmt.Errorf(\"createDocTree exceeds the maximum depth of %d\", maxTemplateDocTreeDepth)\n\t}\n\tvalues, ok := value.([]any)\n\tif !ok {\n\t\treturn nil, errors.New(\"createDocTree definition must be a list\")\n\t}\n\tif 0 == len(values) {\n\t\treturn nil, errors.New(\"createDocTree document list must not be empty\")\n\t}\n\n\tnodes := make([]*TemplateDocTreeNode, 0, len(values))\n\tfor _, value := range values {\n\t\tdefinition, ok := value.(map[string]any)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"createDocTree document must be a dictionary\")\n\t\t}\n\t\tfor key := range definition {\n\t\t\tswitch key {\n\t\t\tcase \"title\", \"template\", \"define\", \"children\":\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"createDocTree document contains unknown field [%s]\", key)\n\t\t\t}\n\t\t}\n\n\t\ttitleValue, ok := definition[\"title\"]\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"createDocTree document title is required\")\n\t\t}\n\t\ttitle, ok := titleValue.(string)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"createDocTree document title must be a string\")\n\t\t}\n\t\ttitle = normalizeDocTitle(title)","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L119-L155","documentation":"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.","triggerScenarios":"Passing definitions like [\"Chapter 1\"] (plain titles) or mixing objects and strings in the list; a children array containing scalars.","commonSituations":"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.","solutions":["Convert each list entry to an object with at least a title, e.g. {\"title\": \"Chapter 1\"}.","If you only have title strings, map them: titles.map(t => ({title: t})).","Verify nested children entries are also dictionaries, not strings."],"exampleFix":"// before\n{\"def\": [\"Chapter 1\", \"Chapter 2\"]}\n// after\n{\"def\": [{\"title\": \"Chapter 1\"}, {\"title\": \"Chapter 2\"}]}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isDocNodeList(list) {\n  return Array.isArray(list) && list.every(n => typeof n === \"object\" && n !== null && !Array.isArray(n) && typeof n.title === \"string\");\n}\nif (!isDocNodeList(def)) throw new Error(\"every entry must be a document object with a title\");","tryCatchPattern":"try {\n  await createDocTree(payload);\n} catch (e) {\n  if (String(e).includes(\"must be a dictionary\")) {\n    // map string entries to {title: s} and retry once\n  } else { throw e; }\n}","preventionTips":["Always wrap plain titles in objects: {title: s}","Validate the whole tree shape (arrays of objects at every level) before sending","Check serializers for leaves stored as plain strings"],"tags":["type-mismatch","validation","json"],"backgroundTag":"incompatible-source-type","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}