{"record":{"id":"b8dc0e1ff6446033","repo":"siyuan-note/siyuan","slug":"msg-fmt-sprintf-conf-language-5-frombox-name","errorCode":null,"errorMessage":"msg = fmt.Sprintf(Conf.Language(5), fromBox.Name, fromPath, err)","messagePattern":"msg = fmt\\.Sprintf\\(Conf\\.Language\\(5\\), fromBox\\.Name, fromPath, err\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":1891,"sourceCode":"\tneedMoveSubDocs := fromBox.Exist(fromFolder)\n\tif needMoveSubDocs {\n\t\t// 移动子文档文件夹\n\n\t\tnewFolder := path.Join(toFolder, tree.ID)\n\t\tif isSameBox {\n\t\t\tif err = fromBox.Move(fromFolder, newFolder); err != nil {\n\t\t\t\treturn\n\t\t\t}\n\t\t} else {\n\t\t\tabsFromPath := filepath.Join(util.DataDir, fromBox.ID, fromFolder)\n\t\t\tabsToPath := filepath.Join(util.DataDir, toBox.ID, newFolder)\n\t\t\tif filelock.IsExist(absToPath) {\n\t\t\t\tfilelock.Remove(absToPath)\n\t\t\t}\n\t\t\tif err = filelock.Rename(absFromPath, absToPath); err != nil {\n\t\t\t\tmsg := fmt.Sprintf(Conf.Language(5), fromBox.Name, fromPath, err)\n\t\t\t\tlogging.LogErrorf(\"move [path=%s] in box [%s] failed: %s\", fromPath, fromBox.ID, err)\n\t\t\t\terr = errors.New(msg)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\tnewPath = path.Join(toFolder, tree.ID+\".sy\")\n\n\tif isSameBox {\n\t\tif err = fromBox.Move(fromPath, newPath); err != nil {\n\t\t\treturn\n\t\t}\n\n\t\ttree, err = filesys.LoadTree(fromBox.ID, newPath, luteEngine)\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\n\t\tmoveTree(tree)","sourceCodeStart":1873,"sourceCodeEnd":1909,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/file.go#L1873-L1909","documentation":"In MoveDocs (kernel/model/file.go:1891), after resolving a name conflict the kernel renames the source .sy file via filelock.Rename. If the OS rename fails (the failed path is first removed at absToPath then the rename is retried), the error is wrapped with localized kernel message 5: 'Move notebook [%s] file [%s] failed: %s'. This is a filesystem-level failure, not a validation error.","triggerScenarios":"filelock.Rename(absFromPath, absToPath) returns an error — source file missing, destination directory not yet created, file locked by antivirus/sync tools, permission problems, or cross-device rename issues.","commonSituations":"The .sy file was deleted or renamed by another client/sync tool between listing and moving; cloud-sync clients (OneDrive/Dropbox) or antivirus holding locks on the file; workspace folder permissions changed; running the kernel without write access to the data dir.","solutions":["Read the wrapped OS error in the message and fix the underlying filesystem cause (missing file, permissions, lock).","Verify the source .sy file exists at data/<boxID>/<fromPath> and that no sync/AV tool is locking it; pause sync tools and retry.","Check the workspace directory permissions (see kernel message 33) and ensure the destination parent folder is writable.","If another client concurrently changed the tree, reload the file tree and repeat the move with fresh paths."],"exampleFix":"// before: blind retry into a possibly missing destination dir\nmoveDocs([\"/a/doc.sy\"], toBoxID, \"/missing-parent\");\n// after: ensure the destination parent doc exists first\ncreateDocWithMd(toBoxID, \"/missing-parent\", \"missing-parent\", \"\");\nmoveDocs([\"/a/doc.sy\"], toBoxID, \"/missing-parent\");","handlingStrategy":"try-catch","validationCode":"const exists = await fetchPost(\"/api/filetree/getHPathByID\", {id: docID});\nif (!exists?.data) throw new Error(\"source document no longer exists; refresh the tree before moving\");","typeGuard":null,"tryCatchPattern":"try {\n  await moveDocs(fromPaths, toBoxID, toPath);\n} catch (e) {\n  const m = String(e.msg);\n  if (m.includes(\"Move notebook\") && m.includes(\"failed\")) {\n    logging.warn(`filesystem move failed: ${m}; refreshing tree and retrying once`);\n    await reloadFiletree();\n    await moveDocs(fromPaths, toBoxID, toPath);\n  } else { throw e; }\n}","preventionTips":["Pause third-party sync clients (OneDrive/Dropbox) pointing at the workspace during bulk moves.","Ensure the workspace folder is user-writable and excluded from antivirus scanning (kernel message 33).","Refresh the file tree before and after bulk operations so paths are current."],"tags":["go","filesystem","rename","move-docs"],"backgroundTag":"file-write-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}