{"record":{"id":"c787debc4edcd52f","repo":"siyuan-note/siyuan","slug":"invalid-notebook-history-path-s","errorCode":null,"errorMessage":"invalid notebook history path [%s]","messagePattern":"invalid notebook history path \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history.go","lineNumber":677,"sourceCode":"\tif filelock.IsExist(to) {\n\t\treturn errors.New(Conf.Language(371))\n\t}\n\n\tif err = filelock.CopyNewtimes(from, to); err != nil {\n\t\tlogging.LogErrorf(\"copy file [%s] to [%s] failed: %s\", from, to, err)\n\t\treturn\n\t}\n\n\tIncSync()\n\tReloadFiletree()\n\tutil.PushMsg(Conf.Language(372), 3000)\n\treturn nil\n}\n\nfunc validateNotebookHistoryPath(historyPath string) (boxID string, err error) {\n\trel, err := filepath.Rel(util.HistoryDir, historyPath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid notebook history path [%s]\", historyPath)\n\t}\n\tparts := strings.Split(filepath.ToSlash(rel), \"/\")\n\tif len(parts) != 2 || !strings.HasSuffix(parts[0], \"-\"+HistoryOpDelete) || !ast.IsNodeIDPattern(parts[1]) ||\n\t\t!gulu.File.IsDir(historyPath) || !filelock.IsExist(filepath.Join(historyPath, \".siyuan\", \"conf.json\")) {\n\t\treturn \"\", fmt.Errorf(\"invalid notebook history path [%s]\", historyPath)\n\t}\n\treturn parts[1], nil\n}\n\nfunc RollbackAttributeViewHistory(historyPath string) (err error) {\n\thistoryPath, err = validateHistoryPath(historyPath)\n\tif err != nil {\n\t\treturn\n\t}\n\t// 验证目标文件必须是 AV 定义文件\n\tif !strings.HasSuffix(historyPath, \".json\") || !strings.Contains(filepath.ToSlash(historyPath), \"/storage/av/\") {\n\t\treturn fmt.Errorf(\"invalid AV history path [%s]\", historyPath)\n\t}","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history.go#L659-L695","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing raw absolute paths from external tooling; mixing workspaces; paths built before the history directory moved between versions.","solutions":["Pass an absolute path located inside the workspace's history directory","Resolve the path against util.HistoryDir before invoking the API","Obtain the path from the notebook history listing API"],"exampleFix":"// before\nrollbackNotebookHistory(\"/var/tmp/snapshots/notebook\")\n// after\nrollbackNotebookHistory(filepath.Join(util.HistoryDir, \"20240101000000-delete-<boxID>\"))","handlingStrategy":"validation","validationCode":"if (!path.resolve(p).startsWith(path.resolve(historyDir))) throw new Error('path must be absolute and under historyDir');","typeGuard":null,"tryCatchPattern":"try { await rollbackNotebookHistory(p); } catch (e) { if (String(e).includes('invalid notebook history path')) { p = path.resolve(historyDir, p); retry(); } else { throw e; } }","preventionTips":["Resolve notebook history paths against the workspace history directory before calling","Use the history listing API to obtain valid absolute paths","Never pass paths from outside the current workspace"],"tags":["history","notebook","validation","path"],"backgroundTag":"invalid-argument-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}