siyuan-note/siyuan · error
get history directory failed
Error message
get history directory failed: %w
What it means
createAssetsHistory begins by obtaining the timestamped history directory via getHistoryDir(HistoryOpUpdate). If that internal step fails (I/O or permission problems creating dirs under history/), the error is wrapped with this prefix and returned, preserving the cause via %w.
Solutions
- Check the wrapped cause (%w) to identify the underlying fs error.
- Ensure <workspace>/history/ is writable by the kernel process.
- Free disk space / fix volume permissions, then retry.
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check writability fs.accessSync(path.join(workspace, "history"), fs.constants.W_OK);
Try / catch
try {
await createAssetHistory(p);
} catch (e) {
if (String(e).includes("get history directory failed")) {
// inspect wrapped cause, fix volume/permission, retry
}
} Prevention
- Keep <workspace>/history writable and on a healthy volume.
- Monitor disk space on the workspace volume.
- Avoid running backup tools that lock or chmod the history dir.
When it happens
Trigger: Any createAssetsHistory call (directly or through CreateAssetHistory / generateAssetsHistory) when the history directory cannot be created: read-only data dir, full disk, permission problems, or history dir occupied by a file.
Common situations: Workspace on a read-only or quota-exceeded volume; restrictive umask/permissions after restoring data with wrong ownership; antivirus locking the history directory.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- create history directory
- read history dir failed
- read history snapshot
- cannot allocate a replacement history directory
- check data.zip failed
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/745ec3feafecc433.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history.go:939
assetAbsPath := filepath.Join(util.DataDir, filepath.FromSlash(assetPath))
assetsDir := filepath.Join(util.DataDir, "assets")
if !gulu.File.IsSubPath(assetsDir, assetAbsPath) {
return errors.New("asset path must be under assets")
}
info, statErr := os.Stat(assetAbsPath)
if statErr != nil {
return statErr
}
if info.IsDir() {
return errors.New("asset path must be a file")
}
return createAssetsHistory([]string{assetAbsPath})
}
func createAssetsHistory(assets []string) (err error) {
historyDir, err := getHistoryDir(HistoryOpUpdate)
if err != nil {
return fmt.Errorf("get history directory failed: %w", err)
}
for _, file := range assets {
assetRelPath, relErr := filepath.Rel(filepath.Join(util.DataDir, "assets"), file)
if relErr != nil || assetRelPath == "." || strings.HasPrefix(assetRelPath, ".."+string(filepath.Separator)) {
return errors.New("asset path must be under assets")
}
historyPath := filepath.Join(historyDir, "assets", assetRelPath)
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {
return fmt.Errorf("create history directory [%s] failed: %w", filepath.Dir(historyPath), err)
}
if copyErr := filelock.Copy(file, historyPath); copyErr != nil {
if os.IsNotExist(copyErr) {
continue
}
return fmt.Errorf("copy asset [%s] to [%s] failed: %w", file, historyPath, copyErr)
}View on GitHub (pinned to 9f775e8a12)