siyuan-note/siyuan · error
create history directory
Error message
create history directory [%s] failed: %w
What it means
Before copying each asset into the history snapshot, createAssetsHistory creates the destination directory history/<stamp>/assets/<rel-dir>. If os.MkdirAll fails, the error is wrapped with the target directory path and returned, aborting the snapshot.
Solutions
- Read the wrapped cause and the [%s] directory in the message to locate the failure.
- Remove any file colliding with the intended history directory path.
- Fix volume writability or shorten paths, then re-run the snapshot.
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure no file collides with the target history dir
if (fs.existsSync(targetDir) && !fs.statSync(targetDir).isDirectory()) {
throw new Error("file blocks history dir: " + targetDir);
} Try / catch
try {
await createAssetHistory(p);
} catch (e) {
if (String(e).includes("create history directory")) {
// parse [%s] dir, clear collision / fix permissions, retry
}
} Prevention
- Keep history dir free of stray files.
- Avoid deep asset nesting to stay under Windows MAX_PATH.
- Watch disk space and volume health.
When it happens
Trigger: MkdirAll failing on the history assets dir: read-only volume, full disk, name collision with an existing file, or path-length limits (long asset names on Windows).
Common situations: History directory made read-only by backup tooling; assets with deep nesting hitting MAX_PATH on Windows; a regular file existing where the directory should be created.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- get history directory failed
- 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/344f26dba31cdf7d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history.go:949
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)
}
}
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
return
}
func (box *Box) generateDocHistory0() {
files := box.recentModifiedDocs()
if 1 > len(files) {
returnView on GitHub (pinned to 9f775e8a12)