siyuan-note/siyuan · error
invalid path
Error message
invalid path
What it means
Returned by `filesys.LoadTreeByData` when, after splitting the hPath on `/`, the result has fewer than two parts. A valid SiYuan document path must contain at least a leading slash plus the document's own segment, so `len(parts) < 2` indicates a malformed path that cannot yield a meaningful hPath.
Source
Thrown at kernel/filesys/tree.go:248
treenode.UpgradeSpec(tree)
escapeAttributeValues(tree)
return
}
func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err error) {
ret, err = parseJSON2Tree(boxID, p, data, luteEngine)
if nil != err {
logging.LogErrorf("parse tree [%s] failed: %s", p, err)
return
}
ret.Path = p
ret.Root.Path = p
hPath := "/" + strings.TrimPrefix(filepath.ToSlash(p), "/")
parts := strings.Split(hPath, "/")
if len(parts) < 2 {
logging.LogErrorf("parse tree [%s] failed: invalid path", p)
err = errors.New("invalid path")
return
}
parts = parts[1 : len(parts)-1] // 去掉开头的斜杆和结尾的自己
if 1 > len(parts) {
ret.HPath = "/" + ret.Root.IALAttr("title")
ret.Hash = treenode.NodeHash(ret.Root, ret, luteEngine)
return
}
// 构造 HPath
hPathBuilder := bytes.Buffer{}
hPathBuilder.WriteString("/")
for i := range parts {
var parentAbsPath string
if 0 < i {
parentAbsPath = strings.Join(parts[:i+1], "/")
} else {View on GitHub (pinned to 251596fc0d)
Solutions
- Ensure `p` is a full box-relative doc path like `20240101000000-abcdef1234567/sub.sy`.
- If generating paths, build them from the parent dir plus the root-ID-based filename.
- Validate the path shape (`strings.Split` yields >= 2 parts) before calling `LoadTreeByData`.
Example fix
// before tree, err := filesys.LoadTreeByData(data, box, "/", lute) // after tree, err := filesys.LoadTreeByData(data, box, "20240101000000-abcdef1234567/page.sy", lute)
Defensive patterns
Strategy: validation
Validate before calling
// Validate the path shape before loading by data:
parts := strings.Split(filepath.ToSlash(p), "/")
if len(parts) < 2 {
return errors.New("invalid path")
} Prevention
- Build doc paths from parent dir + root-ID filename, never from empty placeholders.
- Validate path shape at the trust boundary before reaching filesys internals.
- Unit-test LoadTreeByData with realistic notebook paths.
When it happens
Trigger: Parsing a tree whose `p` is empty, a bare `/`, or otherwise lacks the `/<something>/` shape expected of a doc path inside a notebook.
Common situations: Tree data loaded with an empty or `"/"` path; programmatic construction of `LoadTreeByData` with a placeholder path; import logic that did not set the document path correctly.
Related errors
- custom emoji name must not be empty
- tree is empty
- Untitled
- Cannot create a file starting with .
- Duplicated filename
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/c9e692fff7c7a441.
Report an issue: GitHub.