siyuan-note/siyuan · error

history path [ ] not exist

Error message

history path [%s] not exist

What it means

After confirming the path is inside the workspace, validateHistoryPath checks existence on disk. This error means the normalized history path does not point to an existing file or directory — the history entry was pruned, never created, or the path is mistyped.

Solutions

  1. Re-list available history entries via the history APIs and use a fresh, currently existing path
  2. Check the history retention settings — increase RetentionDays if snapshots are pruned too aggressively
  3. Verify the workspace directory is the one that actually contains the history data

Example fix

// before
rollbackDocHistory(staleHistoryPath) // snapshot already pruned
// after
histories := getHistoryItems(); rollbackDocHistory(histories[0].path) // re-fetched live path
Defensive patterns

Strategy: validation

Validate before calling

if (!fs.existsSync(path.join(workspaceDir, historyPath))) { const fresh = await fetchLatestHistoryEntries(); historyPath = fresh[0].path; }

Try / catch

try { await rollbackDocHistory(p); } catch (e) { if (String(e).includes('not exist')) { await refreshHistoryList(); informUserSnapshotPruned(); } else { throw e; } }

Prevention

When it happens

Trigger: Calling any history read/rollback API with a path under the workspace whose joined absolute path does not exist — typically after history auto-cleanup deleted the snapshot or the caller reused a stale path from a previous session.

Common situations: Cached history paths used after the retention window elapsed and the kernel purged old history; workspaces switched between calls; typos in the timestamp or op segment.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/history.go:609

	if err = filelock.CopyNewtimes(from, to); err != nil {
		logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
		return
	}
	IncSync()
	util.PushMsg(Conf.Language(102), 3000)
	return nil
}

// validateHistoryPath 校验历史路径是否位于工作区内且属于历史目录。
// 拒绝路径穿越攻击(..、绝对路径等)。返回规范化的绝对路径。
func validateHistoryPath(historyPath string) (string, error) {
	p := filepath.Join(util.WorkspaceDir, historyPath)
	if !gulu.File.IsSubPath(util.WorkspaceDir, p) {
		return "", fmt.Errorf("history path [%s] is not in workspace", historyPath)
	}
	if !gulu.File.IsExist(p) {
		return "", fmt.Errorf("history path [%s] not exist", historyPath)
	}
	rel, err := filepath.Rel(util.HistoryDir, p)
	if err != nil || strings.HasPrefix(rel, "..") {
		return "", fmt.Errorf("history path [%s] is not under history directory", historyPath)
	}
	return p, nil
}

// IsEncryptedHistoryPath 判断历史路径是否明确属于加密笔记本。
func IsEncryptedHistoryPath(absPath string) bool {
	boxID := ExtractBoxIDFromHistoryPath(absPath)
	if boxID == "" {
		return false
	}
	if IsEncryptedBox(boxID) {
		return true
	}
	rel, err := filepath.Rel(util.HistoryDir, absPath)

View on GitHub (pinned to 9f775e8a12)