{"record":{"id":"022356b6b4e5ad52","repo":"siyuan-note/siyuan","slug":"renderdocref-path-target-must-be-a-document-path","errorCode":null,"errorMessage":"renderDocRef path target must be a document path","messagePattern":"renderDocRef path target must be a document path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":263,"sourceCode":"\tswitch mode {\n\tcase \"children\":\n\t\tid, ok := value.(string)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"renderDocRef children target must be a document ID\")\n\t\t}\n\t\tif collector.rootID == id {\n\t\t\treturn collector.nodes, nil\n\t\t}\n\t\tfor _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {\n\t\t\tif node.ID == id {\n\t\t\t\treturn node.Children, nil\n\t\t\t}\n\t\t}\n\t\treturn []*TemplateDocTreeNode{}, nil\n\tcase \"path\":\n\t\thPath, ok := value.(string)\n\t\tif !ok {\n\t\t\treturn \"\", errors.New(\"renderDocRef path target must be a document path\")\n\t\t}\n\t\trequestedPath := path.Clean(hPath)\n\t\tfor _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {\n\t\t\trelativePath := strings.TrimPrefix(node.HPath, collector.rootHPath)\n\t\t\tif node.HPath == requestedPath || relativePath == requestedPath {\n\t\t\t\treturn fmt.Sprintf(\"((%s %q))\", node.RootID, node.HPath), nil\n\t\t\t}\n\t\t}\n\t\treturn \"\", nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported renderDocRef query mode [%s]\", mode)\n\t}\n}\n\nfunc flattenTemplateDocTreeNodes0(nodes []*TemplateDocTreeNode) (ret []*TemplateDocTreeNode) {\n\tfor _, node := range nodes {\n\t\tret = append(ret, node)\n\t\tret = append(ret, flattenTemplateDocTreeNodes0(node.Children)...)","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L245-L281","documentation":"In renderDocRef mode 'path', the query value must be a document HPath string. The collector cleans the value and matches it against the collected nodes' paths; a non-string value cannot be interpreted as a path and triggers this error.","triggerScenarios":"A template's renderDocRef action with mode \"path\" receives a non-string value — e.g. a number, list, or nil result of an expression — instead of a document path string.","commonSituations":"Unquoted or malformed path arguments in templates; expressions returning structured values; mixing up the 'children' (ID) and 'path' modes and passing a non-string ID.","solutions":["Pass the document path as a quoted string, e.g. \"/foo/bar\"","Check that any expression feeding the value yields a string","Ensure you are not passing an ID where a path is expected (or vice versa)"],"exampleFix":"// before\n{{renderDocRef \"path\" someObject}}\n// after\n{{renderDocRef \"path\" \"/parent/child\"}}","handlingStrategy":"validation","validationCode":"if v, ok := value.(string); !ok || !strings.HasPrefix(v, \"/\") { return fmt.Errorf(\"path target must be a path string\") }","typeGuard":"func isHPath(v any) bool { s, ok := v.(string); return ok && strings.HasPrefix(s, \"/\") }","tryCatchPattern":"out, err := collector.renderDocRef(\"path\", value)\nif err != nil && strings.Contains(err.Error(), \"path target must be a document path\") {\n  // fix the value to a string path\n}","preventionTips":["Quote path arguments in templates","Use leading '/' for absolute HPaths","Do not pass IDs into the 'path' mode"],"tags":["go","template","type-error"],"backgroundTag":"type-mismatch","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"}