siyuan-note/siyuan · error
invalid notebook history path [%s]
Error message
invalid notebook history path [%s]
What it means
validateNotebookHistoryPath only accepts paths that are exactly two segments relative to data/history: '<timestamp>-deleted/<boxID>' where the op suffix is the delete operation, the box ID matches the node-ID pattern, the path is a directory, and it contains .siyuan/conf.json. A Rel computation failure (path not under HistoryDir) produces this error before those structural checks.
Source
Thrown at kernel/model/history.go:661
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 8641553a1f)
Solutions
- Pass a path of the form data/history/<timestamp>-deleted/<boxID> taken directly from the notebook-history listing API
- Ensure the history directory contains .siyuan/conf.json — if the copy lost it, restore the full snapshot including .siyuan
- Use /api/history/rollbackDocHistory or rollbackAssetsHistory for non-notebook histories, not rollbackNotebookHistory
Example fix
// before: doc history path given to notebook rollback
rollbackNotebookHistory("history/20240101120000-update/<boxID>/<docID>.sy")
// after: proper deleted-notebook history path
rollbackNotebookHistory("history/20240101120000-deleted/<boxID>") Defensive patterns
Strategy: validation
Validate before calling
function looksLikeNotebookHistory(historyPath) {
const parts = historyPath.replace(/\\/g, "/").split("/");
return parts.length === 2 && parts[0].endsWith("-deleted") && /^[0-9a-z]{20}$/.test(parts[1]);
} Type guard
null
Try / catch
try { await rollbackNotebookHistory(p); } catch (e) { if (String(e.msg).startsWith("invalid notebook history path")) { /* route to the correct rollback API by path shape */ } else { throw e; } } Prevention
- Pick the rollback endpoint based on the history item type from the listing API
- Keep the .siyuan directory intact when copying history snapshots
- Use API-returned paths, not hand-assembled ones
When it happens
Trigger: Calling RollbackNotebookHistory with a path outside data/history (Rel fails), a doc or asset history path, or a malformed notebook history folder (wrong depth, wrong op suffix, missing .siyuan/conf.json).
Common situations: Passing a document history path to the notebook rollback API by mistake; manually copied notebook history missing the .siyuan directory; history from a custom backup tool laid out differently; API misuse mixing rollback endpoints.
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
- encrypted asset history is missing valid notebook context
- history path [%s] is not under history directory
- Conf.Language(371)
- invalid AV history path [%s]
- encrypted attribute view history is missing valid notebook c
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/c787debc4edcd52f.
Report an issue: GitHub.