siyuan-note/siyuan · error

read dir [ ] failed

Error message

read dir [%s] failed: %w

What it means

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.

Solutions

  1. Verify the directory exists on disk at <workspace>/data/<boxID>/<parentPath> and recreate or restore it if missing
  2. Check OS read permissions on the directory (chown/chmod) and that the disk is not read-only
  3. Refresh/Reindex the notebook (rebuild) so stale paths in the block tree are reconciled with disk
  4. Exclude the workspace from external sync tools or pause them while SiYuan runs

Example fix

// before: caller ignores path validity
order, err := loadSiblingCustomOrder(boxID, parentPath, fullSortIDs)
// after: caller pre-checks the directory
absParent := filepath.Join(util.DataDir, boxID, parentPath)
if _, statErr := os.Stat(absParent); statErr != nil {
    return nil, fmt.Errorf("parent dir unavailable: %w", statErr)
}
order, err := loadSiblingCustomOrder(boxID, parentPath, fullSortIDs)
Defensive patterns

Strategy: try-catch

Validate before calling

const absParent = require('path').join(dataDir, boxID, parentPath);
if (!fs.existsSync(absParent)) throw new Error(`missing dir: ${absParent}`);

Try / catch

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; } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/8a4f0bd0658c39c4. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/file.go:2769

			return fmt.Errorf("target ID [%s] must not be included in source IDs", targetID)
		}
		if _, ok := seen[sourceID]; ok {
			return fmt.Errorf("duplicate source ID [%s]", sourceID)
		}
		seen[sourceID] = struct{}{}
	}
	return nil
}

func isSortableDocument(tree *treenode.BlockTree) bool {
	return nil != tree && tree.ID == tree.RootID && "d" == tree.Type && !IsBoxDoc(tree.BoxID, tree.RootID)
}

func loadSiblingCustomOrder(boxID, parentPath string, fullSortIDs map[string]int) (ret []string, err error) {
	absParentPath := filepath.Join(util.DataDir, boxID, parentPath)
	files, err := os.ReadDir(absParentPath)
	if nil != err {
		return nil, fmt.Errorf("read dir [%s] failed: %w", absParentPath, err)
	}
	for _, file := range files {
		if file.IsDir() || !strings.HasSuffix(file.Name(), ".sy") {
			continue
		}
		id := strings.TrimSuffix(file.Name(), ".sy")
		if !ast.IsNodeIDPattern(id) || ("/" == parentPath && id == boxID) {
			continue
		}
		ret = append(ret, id)
	}
	sort.Slice(ret, func(i, j int) bool {
		leftSort, rightSort := fullSortIDs[ret[i]], fullSortIDs[ret[j]]
		if leftSort != rightSort {
			return leftSort < rightSort
		}
		leftTime, rightTime := util.TimeFromID(ret[i]), util.TimeFromID(ret[j])
		if leftTime != rightTime {

View on GitHub (pinned to 9f775e8a12)