siyuan-note/siyuan · error
invalid AV history path
Error message
invalid AV history path [%s]
What it means
RollbackAttributeViewHistory validates that the supplied history archive path points at an attribute-view definition snapshot before attempting a rollback. The path must end in .json and contain the /storage/av/ segment; otherwise the kernel refuses to treat it as an AV history artifact and returns this error. It guards against rolling back arbitrary files as if they were AV snapshots.
Solutions
- Pass the exact history path returned by the AV history listing API (a *.json file under history/<timestamp>/storage/av/).
- Verify the path ends with .json and its ToSlash form contains /storage/av/ before calling.
- If migrating old data, re-derive the path from the history index instead of reusing stored raw paths.
Example fix
// before
rollbackHistory("history/20260101120000/storage/av/20260101120000")
// after
rollbackHistory("history/20260101120000/storage/av/20260101120000.json") Defensive patterns
Strategy: validation
Validate before calling
const p = filepath.ToSlash(filepath.Clean(historyPath));
if (!p.endsWith(".json") || !p.includes("/storage/av/")) {
throw new Error("not an AV history path: " + p);
} Type guard
function isAvHistoryPath(p) {
const s = filepath.ToSlash(p);
return s.endsWith(".json") && s.includes("/storage/av/");
} Prevention
- Always take the history path from the AV history listing API, never from user input.
- Normalize to forward slashes before validating on Windows.
- Keep a smoke test that rolls back a known-good AV snapshot.
When it happens
Trigger: Calling RollbackAttributeViewHistory with a path that is not a .json file, or a path whose slash-normalized form does not contain /storage/av/ (e.g. a document history path, an arbitrary user path, or a path with backslashes on Windows that fails normalization).
Common situations: Plugin or script code passes a doc-history path instead of an AV history path; hand-crafted history paths from an older SiYuan version with a different layout; Windows path separators leaking into the check.
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
- database history contains an invalid group
- database history contains an invalid view
- database history has no primary field
- encrypted attribute view history is missing valid notebook…
- invalid notebook history path
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a03636d5a6bddd15.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history.go:694
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)
}
from := historyPath
// 从路径提取 boxID 判断是否加密笔记本的 AV
relPath := strings.TrimPrefix(filepath.ToSlash(historyPath), filepath.ToSlash(util.HistoryDir))
relPath = strings.TrimPrefix(relPath, "/")
pathParts := strings.SplitN(relPath, "/", 3)
data, readErr := filelock.ReadFile(from)
if readErr != nil {
return readErr
}
ciphertext := util.IsCiphertext(data)
if ciphertext && (len(pathParts) < 3 || !ast.IsNodeIDPattern(pathParts[1]) || !IsEncryptedBox(pathParts[1])) {
return errors.New("encrypted attribute view history is missing valid notebook context")
}
to := filepath.Join(util.DataDir, "storage", "av", filepath.Base(historyPath))
if len(pathParts) >= 2 && IsEncryptedBox(pathParts[1]) {
if !ciphertext {View on GitHub (pinned to 9f775e8a12)