{"record":{"id":"be6cc0978e6d2084","repo":"siyuan-note/siyuan","slug":"errinvalidid","errorCode":"ErrInvalidID","errorMessage":"invalid id","messagePattern":"invalid id","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/tree.go","lineNumber":216,"sourceCode":"\tif err = treenode.CheckSpecJSON(data); nil != err {\n\t\treturn\n\t}\n\tret, err = dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"parse json to tree [%s] failed: %s\", localPath, err)\n\t\treturn\n\t}\n\treturn\n}\n\nvar (\n\tErrBoxNotFound   = errors.New(\"notebook not found\")\n\tErrBoxClosed     = errors.New(\"notebook closed\")\n\tErrBlockNotFound = errors.New(\"block not found\")\n\tErrTreeNotFound  = errors.New(\"tree not found\")\n\tErrIndexing      = errors.New(\"indexing\")\n\tErrBoxUnindexed  = errors.New(\"notebook unindexed\")\n\tErrInvalidID     = errors.New(\"invalid id\")\n)\n\nfunc LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {\n\treturn LoadTreeByBlockIDWithReindexInBox(id, \"\")\n}\n\n// LoadTreeByBlockIDWithReindexInBox 与 LoadTreeByBlockIDWithReindex 一致，但按 boxID 路由 blocktree 查询。\nfunc LoadTreeByBlockIDWithReindexInBox(id, boxID string) (ret *parse.Tree, err error) {\n\tif \"\" == id {\n\t\tlogging.LogWarnf(\"block id is empty\")\n\t\treturn nil, ErrTreeNotFound\n\t}\n\n\tbt := treenode.GetBlockTreeInBox(id, boxID)\n\tif nil == bt && \"\" == boxID {\n\t\t// boxID 未知时（如通用打开入口），遍历所有已打开的加密笔记本查找\n\t\tfor _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {\n\t\t\tif encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/tree.go#L198-L234","documentation":"ErrInvalidID is a sentinel error meaning the supplied ID string does not match SiYuan's node-ID format (ast.IsNodeIDPattern). The kernel validates IDs before doing any database or repository work to fail fast on malformed input. It is returned by attribute-view rendering and repo-snapshot resolution APIs, among others.","triggerScenarios":"Calling RenderAttributeViewWithTarget or ResolveRepoSnapshotAttributeViewBoxID (and other ID-validating model functions) with an avID/blockID that is not a well-formed node ID (wrong length, illegal characters, empty string).","commonSituations":"Passing a database/attribute-view name instead of its ID; truncated or hand-edited IDs; plugins constructing IDs programmatically without the ID generator; stale client code after a block was recreated with a new ID.","solutions":["Validate the ID client-side against the SiYuan ID pattern before calling the API","Fetch the correct ID via the list/query APIs (e.g. /api/attrv/getAttrView or SQL search) instead of hard-coding it","Check whether the ID was truncated or mangled by serialization/URL handling","Match with errors.Is(err, model.ErrInvalidID) and return a 'bad identifier' message to the caller"],"exampleFix":"// before\nviewable, av, _, err := model.RenderAttributeViewWithTarget(avID, ...)\n// after\nif !ast.IsNodeIDPattern(avID) {\n    return fmt.Errorf(\"invalid attribute view ID: %q\", avID)\n}\nviewable, av, _, err := model.RenderAttributeViewWithTarget(avID, ...)","handlingStrategy":"validation","validationCode":"func isValidSiYuanID(id string) bool { return ast.IsNodeIDPattern(id) }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if errors.Is(err, model.ErrInvalidID) {\n        return fmt.Errorf(\"bad identifier %q: %w\", avID, err)\n    }\n    return err\n}","preventionTips":["Always obtain IDs from kernel APIs, never construct them by hand","Validate IDs with ast.IsNodeIDPattern before calling model functions","Beware truncation when storing IDs in URLs or configs"],"tags":["go","identifier","validation"],"backgroundTag":"invalid-identifier-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"}