{"record":{"id":"034aab3e306ae38d","repo":"siyuan-note/siyuan","slug":"write-data-s-failed-s","errorCode":null,"errorMessage":"write data [%s] failed: %s","messagePattern":"write data \\[(.+?)\\] failed: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/filesys/tree.go","lineNumber":440,"sourceCode":"\t\t}\n\t}\n\n\tif util.ExceedLargeFileWarningSize(len(data)) {\n\t\tmsg := fmt.Sprintf(util.Langs[util.Lang][268], tree.Root.IALAttr(\"title\")+\" \"+filepath.Base(filePath), util.LargeFileWarningSize)\n\t\tutil.PushErrMsg(msg, 7000)\n\t}\n\n\tcache.SetTreeDataInBox(tree.ID, tree.Box, data)\n\tafterWriteTree(tree)\n\tsize = uint64(len(data))\n\treturn\n}\n\nfunc writeTreeByWriteFile(filePath string, data []byte) (err error) {\n\tif err = filelock.WriteFile(filePath, data); err != nil {\n\t\tmsg := fmt.Sprintf(\"write data [%s] failed: %s\", filePath, err)\n\t\tlogging.LogErrorf(\"%s\", msg)\n\t\terr = errors.New(msg)\n\t\treturn\n\t}\n\treturn\n}\n\nfunc prepareWriteTree(tree *parse.Tree) (data []byte, filePath string, err error) {\n\tluteEngine := util.NewLute() // 不关注用户的自定义解析渲染选项\n\n\tif nil == tree.Root.FirstChild {\n\t\tnewP := treenode.NewParagraph(\"\")\n\t\ttree.Root.AppendChild(newP)\n\t\ttree.Root.SetIALAttr(\"updated\", util.TimeFromID(newP.ID))\n\t\ttreenode.UpsertBlockTree(tree)\n\t}\n\n\ttreenode.UpgradeSpec(tree)\n\n\tif _, err = ValidateBoxRelativePath(tree.Box, tree.Path); err != nil {","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/filesys/tree.go#L422-L458","documentation":"Returned by `writeTreeByWriteFile` when `filelock.WriteFile(filePath, data)` fails. The underlying error is wrapped into a descriptive message that includes the file path and the original error, then logged via `logging.LogErrorf` before being returned. This is the I/O failure path for persisting a `.sy` tree to disk.","triggerScenarios":"Disk full, permission denied, read-only filesystem, file locked by another process, or the parent directory removed mid-write. Any error from `filelock.WriteFile` is funneled into this message.","commonSituations":"Synchronizing to a full disk; antivirus/filelock contention on Windows; running on a read-only mount; path to a directory that no longer exists after a move.","solutions":["Free disk space and retry the write.","Check filesystem permissions on `data/` and the target box directory.","Inspect the wrapped error in the log for the specific OS error (ENOENT, EACCES, etc.) and address it.","If a stale lock is suspected, ensure no other SiYuan kernel is running against the same workspace."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check writability when possible:\nif err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := filesys.WriteTree(tree); err != nil {\n    if strings.Contains(err.Error(), \"write data\") {\n        // surface the wrapped OS error to the user; offer retry/history restore\n    }\n    return err\n}","preventionTips":["Monitor free disk space on the workspace volume.","Ensure the data dir and box dirs are writable by the kernel process.","Avoid running two kernels against one workspace to prevent file-lock contention."],"tags":["filesystem","io","write","tree"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}