siyuan-note/siyuan · error
parse parent document
Error message
parse parent document [%s]: %w
What it means
readDocIAL extracts the document ID and properties from a .sy JSON file, optionally in strict mode. When json.Unmarshal fails on the file's bytes, the error is wrapped as "parse parent document [%s]: %w" so the caller knows which file failed and why. The wrapping distinguishes parse failures from a merely missing parent document.
Solutions
- Open the .sy file at the reported path and fix or inspect its JSON validity.
- Restore the corrupted document from sync snapshots, file history, or backup.
- Re-index or rebuild the document if the corruption is unrecoverable from backups.
- Check disk health/space if the file was truncated mid-write.
Example fix
// no code fix — repair the data // before: data/<box>/20260101120000-abc.sy contains truncated JSON // after: restore a valid .sy from history/backup, then retry the operation
Defensive patterns
Strategy: try-catch
Validate before calling
try { JSON.parse(require("fs").readFileSync(syPath, "utf8")); } catch (e) { /* file is corrupt; restore before proceeding */ } Try / catch
ials, err := filesys.ReadDocHPath(absPath)
if err != nil {
var pathErr *fs.PathError
if errors.As(err, &pathErr) { /* parent missing: safe to rebuild */ }
// otherwise parse/corruption error: restore from history or backup
} Prevention
- Keep file history/sync snapshots enabled so corrupted .sy files are recoverable.
- Avoid editing .sy files with external tools.
- Monitor disk space; truncated JSON usually comes from interrupted writes.
When it happens
Trigger: Reading a parent document whose JSON is truncated, corrupted (e.g. interrupted write or failed sync), not UTF-8, or has a top-level structure that cannot unmarshal into {ID, Type, Properties}.
Common situations: Partial .sy files after a crash or disk-full during write; merge/sync conflicts producing invalid JSON; manually edited documents with JSON syntax errors; byte-level corruption on disk.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- decode existing session data failed
- invalid attribute view JSON
- invalid document JSON
- parse encrypted notebook history conf
- read attribute view custom color usage
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/0c5554c85c6cab08.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/filesys/tree.go:361
if err != nil {
return nil, err
}
data, err = decryptDataWithDEK(boxID, filepath.ToSlash(relPath), data, dek)
if err != nil {
return nil, err
}
if strict {
if err = treenode.CheckSpecJSON(data); err != nil {
return nil, err
}
}
var doc struct {
ID string
Type string
Properties map[string]string
}
if err = json.Unmarshal(data, &doc); err != nil {
return nil, fmt.Errorf("parse parent document [%s]: %w", absPath, err)
}
if strict && (doc.ID != util.GetTreeID(absPath) || doc.Type != "NodeDocument") {
return nil, fmt.Errorf("invalid document identity [%s]", absPath)
}
if len(doc.Properties) == 0 {
return nil, fmt.Errorf("missing parent document properties [%s]", absPath)
}
for key, value := range doc.Properties {
doc.Properties[key] = html.UnescapeAttrVal(value)
}
return doc.Properties, nil
}
func DocIAL(absPath string) (ret map[string]string) {
// 加密笔记本的 .sy 是密文,流式 jsoniter 解析无法处理,需先整体读+解密。
// 反推 boxID:路径形如 <DataDir>/<boxID>/...;非加密笔记本走原流式逻辑。
boxID := docIALBoxID(absPath)
if boxID != "" && DEKProvider != nil {View on GitHub (pinned to 9f775e8a12)