siyuan-note/siyuan · error
renderDocRef path target must be a document path
Error message
renderDocRef path target must be a document path
What it means
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.
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)
Example fix
// before
{{renderDocRef "path" someObject}}
// after
{{renderDocRef "path" "/parent/child"}} Defensive patterns
Strategy: validation
Validate before calling
if v, ok := value.(string); !ok || !strings.HasPrefix(v, "/") { return fmt.Errorf("path target must be a path string") } Type guard
func isHPath(v any) bool { s, ok := v.(string); return ok && strings.HasPrefix(s, "/") } Try / catch
out, err := collector.renderDocRef("path", value)
if err != nil && strings.Contains(err.Error(), "path target must be a document path") {
// fix the value to a string path
} Prevention
- Quote path arguments in templates
- Use leading '/' for absolute HPaths
- Do not pass IDs into the 'path' mode
When it happens
Trigger: 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.
Common situations: 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.
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
- renderDocRef children target must be a document ID
- attribute view [ ] not found in box [ ]
- attribute view [ ] template plan not found
- child template definition
- child template [ ] not found in the current template package
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/022356b6b4e5ad52.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:263
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)
if node.HPath == requestedPath || relativePath == requestedPath {
return fmt.Sprintf("((%s %q))", node.RootID, node.HPath), nil
}
}
return "", nil
default:
return nil, fmt.Errorf("unsupported renderDocRef query mode [%s]", mode)
}
}
func flattenTemplateDocTreeNodes0(nodes []*TemplateDocTreeNode) (ret []*TemplateDocTreeNode) {
for _, node := range nodes {
ret = append(ret, node)
ret = append(ret, flattenTemplateDocTreeNodes0(node.Children)...)View on GitHub (pinned to 9f775e8a12)