siyuan-note/siyuan · error
read document [ ] failed
Error message
read document [%s] failed: %w
What it means
generateDocHistoryFile wraps the underlying OS error returned by filelock.ReadFile when it cannot read the .sy document file for which a history snapshot is being generated. The wrapper preserves the original error (e.g. permission denied, I/O error) while adding the failing file path. Note that os.IsNotExist is deliberately treated as a benign no-op (return nil), so this error only fires for real read failures of an existing file.
Solutions
- Check the wrapped cause (%w) in the error message; it names the actual OS failure - fix that root cause first (permissions, disk, lock).
- Run the kernel process with an account that has read access to the workspace data directory.
- Close programs that lock workspace files (backup/AV/sync clients) or exclude the workspace from them.
- Verify the workspace is on a healthy local disk, not an unreliable network mount.
- Re-trigger history generation; if the file is now gone, the code treats not-exist as success.
Example fix
// caller in generateDocHistory0
if err := generateDocHistoryFile(boxID, file, historyDir, luteEngine); err != nil {
logging.LogErrorf("generate doc history for [%s] failed: %v", file, err)
// surface the wrapped cause instead of swallowing it
return fmt.Errorf("history generation aborted: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(file); err != nil {
if os.IsNotExist(err) {
return nil // benign, matches kernel behavior
}
return fmt.Errorf("document file unreadable before history generation: %w", err)
} Try / catch
if err := generateDocHistoryFile(boxID, file, historyDir, luteEngine); err != nil {
var perr *fs.PathError
if errors.As(err, &perr) {
logging.LogErrorf("read failed for %s: %v", perr.Path, perr.Err)
}
return err
} Prevention
- Keep the workspace on a healthy local disk and exclude it from aggressive AV/backup lockers
- Run the kernel with sufficient file permissions on data/
- Avoid concurrent tools that move/delete workspace files while SiYuan runs
When it happens
Trigger: generateDocHistoryFile -> filelock.ReadFile(file) fails with an error other than os.IsNotExist: the file exists but is unreadable (permissions changed mid-operation), locked by another process with a hard error, on a failing disk, or the path became invalid between the directory listing and the read (race with file deletion on platforms where ReadFile reports a non-ENOENT error).
Common situations: Sync or external tools altered file permissions inside data/<box>/; antivirus or backup software holds the file; disk full/corrupt sectors; the file was removed by another goroutine (sync/rollback) between listing and reading; network/CloudDrive-synced workspace briefly made files unavailable with an error other than not-exist.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- cannot allocate a replacement history directory
- create history directory
- get history directory failed
- read encrypted notebook history conf
- read history dir failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/aa2ba0aa7b2f5c77.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history.go:994
luteEngine := util.NewLute()
for _, file := range files {
if err = generateDocHistoryFile(box.ID, file, historyDir, luteEngine); err != nil {
logging.LogErrorf("generate history failed: %s", err)
return
}
}
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
return
}
func generateDocHistoryFile(boxID, file, historyDir string, luteEngine *lute.Lute) error {
data, err := filelock.ReadFile(file)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return fmt.Errorf("read document [%s] failed: %w", file, err)
}
return generateDocHistoryFromData(boxID, file, historyDir, data, luteEngine)
}
func generateDocHistoryFromData(boxID, file, historyDir string, data []byte, luteEngine *lute.Lute) error {
historyPath := filepath.Join(historyDir, boxID, strings.TrimPrefix(file, filepath.Join(util.DataDir, boxID)))
if err := os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {
return err
}
if err := gulu.File.WriteFileSafer(historyPath, data, 0644); err != nil {
return err
}
if !strings.HasSuffix(file, ".sy") {
return nil
}
tree, err := loadTreeByData(file, data, luteEngine)View on GitHub (pinned to 9f775e8a12)