siyuan-note/siyuan · error

invalid notebook history path

Error message

invalid notebook history path [%s]

What it means

validateNotebookHistoryPath computes the path relative to util.HistoryDir; if that fails (e.g. the path is not under the history directory at all), it rejects the input with this error. This is the first of two validation gates for notebook history rollbacks.

Solutions

  1. Pass an absolute path located inside the workspace's history directory
  2. Resolve the path against util.HistoryDir before invoking the API
  3. Obtain the path from the notebook history listing API

Example fix

// before
rollbackNotebookHistory("/var/tmp/snapshots/notebook")
// after
rollbackNotebookHistory(filepath.Join(util.HistoryDir, "20240101000000-delete-<boxID>"))
Defensive patterns

Strategy: validation

Validate before calling

if (!path.resolve(p).startsWith(path.resolve(historyDir))) throw new Error('path must be absolute and under historyDir');

Try / catch

try { await rollbackNotebookHistory(p); } catch (e) { if (String(e).includes('invalid notebook history path')) { p = path.resolve(historyDir, p); retry(); } else { throw e; } }

Prevention

When it happens

Trigger: Calling RollbackNotebookHistory with a path outside util.HistoryDir, such as an absolute path elsewhere on disk, so filepath.Rel(util.HistoryDir, historyPath) returns an error.

Common situations: Passing raw absolute paths from external tooling; mixing workspaces; paths built before the history directory moved between versions.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/history.go:677

	if filelock.IsExist(to) {
		return errors.New(Conf.Language(371))
	}

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

	IncSync()
	ReloadFiletree()
	util.PushMsg(Conf.Language(372), 3000)
	return nil
}

func validateNotebookHistoryPath(historyPath string) (boxID string, err error) {
	rel, err := filepath.Rel(util.HistoryDir, historyPath)
	if err != nil {
		return "", fmt.Errorf("invalid notebook history path [%s]", historyPath)
	}
	parts := strings.Split(filepath.ToSlash(rel), "/")
	if len(parts) != 2 || !strings.HasSuffix(parts[0], "-"+HistoryOpDelete) || !ast.IsNodeIDPattern(parts[1]) ||
		!gulu.File.IsDir(historyPath) || !filelock.IsExist(filepath.Join(historyPath, ".siyuan", "conf.json")) {
		return "", fmt.Errorf("invalid notebook history path [%s]", historyPath)
	}
	return parts[1], nil
}

func RollbackAttributeViewHistory(historyPath string) (err error) {
	historyPath, err = validateHistoryPath(historyPath)
	if err != nil {
		return
	}
	// 验证目标文件必须是 AV 定义文件
	if !strings.HasSuffix(historyPath, ".json") || !strings.Contains(filepath.ToSlash(historyPath), "/storage/av/") {
		return fmt.Errorf("invalid AV history path [%s]", historyPath)
	}

View on GitHub (pinned to 9f775e8a12)