{"record":{"id":"8a4f0bd0658c39c4","repo":"siyuan-note/siyuan","slug":"read-dir-s-failed-w","errorCode":null,"errorMessage":"read dir [%s] failed: %w","messagePattern":"read dir \\[(.+?)\\] failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2769,"sourceCode":"\t\t\treturn fmt.Errorf(\"target ID [%s] must not be included in source IDs\", targetID)\n\t\t}\n\t\tif _, ok := seen[sourceID]; ok {\n\t\t\treturn fmt.Errorf(\"duplicate source ID [%s]\", sourceID)\n\t\t}\n\t\tseen[sourceID] = struct{}{}\n\t}\n\treturn nil\n}\n\nfunc isSortableDocument(tree *treenode.BlockTree) bool {\n\treturn nil != tree && tree.ID == tree.RootID && \"d\" == tree.Type && !IsBoxDoc(tree.BoxID, tree.RootID)\n}\n\nfunc loadSiblingCustomOrder(boxID, parentPath string, fullSortIDs map[string]int) (ret []string, err error) {\n\tabsParentPath := filepath.Join(util.DataDir, boxID, parentPath)\n\tfiles, err := os.ReadDir(absParentPath)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"read dir [%s] failed: %w\", absParentPath, err)\n\t}\n\tfor _, file := range files {\n\t\tif file.IsDir() || !strings.HasSuffix(file.Name(), \".sy\") {\n\t\t\tcontinue\n\t\t}\n\t\tid := strings.TrimSuffix(file.Name(), \".sy\")\n\t\tif !ast.IsNodeIDPattern(id) || (\"/\" == parentPath && id == boxID) {\n\t\t\tcontinue\n\t\t}\n\t\tret = append(ret, id)\n\t}\n\tsort.Slice(ret, func(i, j int) bool {\n\t\tleftSort, rightSort := fullSortIDs[ret[i]], fullSortIDs[ret[j]]\n\t\tif leftSort != rightSort {\n\t\t\treturn leftSort < rightSort\n\t\t}\n\t\tleftTime, rightTime := util.TimeFromID(ret[i]), util.TimeFromID(ret[j])\n\t\tif leftTime != rightTime {","sourceCodeStart":2751,"sourceCodeEnd":2787,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2751-L2787","documentation":"loadSiblingCustomOrder reads the parent directory of a document from disk (os.ReadDir) to discover sibling .sy files and rebuild the custom sort order. If the OS-level directory read fails, the raw os error is wrapped with \"read dir [%s] failed: %w\" so the absolute path of the unreadable directory is preserved. This is a filesystem I/O failure, not a data-structure problem.","triggerScenarios":"Calling the custom-sort load path (e.g. sorting documents by custom order) when absParentPath = filepath.Join(util.DataDir, boxID, parentPath) does not exist, was deleted, or the process lacks read permission; the parent .sy file exists in the block tree but its directory is gone from disk.","commonSituations":"Workspace synced/moved while the kernel holds a stale path; notebook folder manually deleted or renamed outside SiYuan; OneDrive/Dropbox sync placeholders not hydrated; read-permission loss after user/group changes; running on a read-only mounted workspace.","solutions":["Verify the directory exists on disk at <workspace>/data/<boxID>/<parentPath> and recreate or restore it if missing","Check OS read permissions on the directory (chown/chmod) and that the disk is not read-only","Refresh/Reindex the notebook (rebuild) so stale paths in the block tree are reconciled with disk","Exclude the workspace from external sync tools or pause them while SiYuan runs"],"exampleFix":"// before: caller ignores path validity\norder, err := loadSiblingCustomOrder(boxID, parentPath, fullSortIDs)\n// after: caller pre-checks the directory\nabsParent := filepath.Join(util.DataDir, boxID, parentPath)\nif _, statErr := os.Stat(absParent); statErr != nil {\n    return nil, fmt.Errorf(\"parent dir unavailable: %w\", statErr)\n}\norder, err := loadSiblingCustomOrder(boxID, parentPath, fullSortIDs)","handlingStrategy":"try-catch","validationCode":"const absParent = require('path').join(dataDir, boxID, parentPath);\nif (!fs.existsSync(absParent)) throw new Error(`missing dir: ${absParent}`);","typeGuard":null,"tryCatchPattern":"try { order = await api.loadSiblingCustomOrder(boxID, parentPath); } catch (e) { if (String(e).includes('read dir')) { await api.reindex(boxID); order = await api.loadSiblingCustomOrder(boxID, parentPath); } else { throw e; } }","preventionTips":["Do not delete or rename notebook folders under data/ while the kernel runs","Exclude the workspace from cloud-sync placeholder services (OneDrive/Dropbox)","Verify workspace disk mount is writable and not read-only before batch operations","Rebuild indexes after any external manipulation of the data directory"],"tags":["go","filesystem","io","directory"],"backgroundTag":"directory-not-found","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}