{"record":{"id":"ec7af382c45d42ab","repo":"siyuan-note/siyuan","slug":"errinvalidboxid","errorCode":"ErrInvalidBoxID","errorMessage":"invalid box id","messagePattern":"invalid box id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/av.go","lineNumber":1385,"sourceCode":"\tav := filepath.Join(util.DataDir, \"storage\", \"av\")\n\tret = filepath.Join(av, avID+\".json\")\n\tif !gulu.File.IsDir(av) {\n\t\tif err := os.MkdirAll(av, 0755); err != nil {\n\t\t\tlogging.LogErrorf(\"create attribute view dir failed: %s\", err)\n\t\t\treturn\n\t\t}\n\t}\n\treturn\n}\n\nfunc GetAttributeViewI18n(key string) string {\n\treturn util.AttrViewLangs[util.Lang][key].(string)\n}\n\nvar (\n\tErrAttributeViewNotFound  = errors.New(\"attribute view not found\")\n\tErrInvalidAttributeViewID = errors.New(\"invalid attribute view id\")\n\tErrInvalidBoxID           = errors.New(\"invalid box id\")\n\tErrViewNotFound           = errors.New(\"view not found\")\n\tErrKeyNotFound            = errors.New(\"key not found\")\n\tErrItemNotFound           = errors.New(\"item not found\")\n\tErrWrongLayoutType        = errors.New(\"wrong layout type\")\n\tErrInvalidColumnAlign     = errors.New(\"invalid column align\")\n\tErrSpecTooNew             = errors.New(\"attribute view spec is too new\")\n\tErrRichTextSpecMismatch   = errors.New(\"attribute view rich text requires storage spec 9\")\n\tErrFilterTooDeep          = errors.New(\"filter nesting depth exceeds the maximum allowed\")\n)\n\nconst (\n\tNodeAttrNameAvs        = \"custom-avs\"                  // 用于标记块所属的属性视图，逗号分隔 av id\n\tNodeAttrView           = \"custom-sy-av-view\"           // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443\n\tNodeAttrVisibleViewIDs = \"custom-sy-av-visible-views\"  // 用于标记数据库块显示的视图 ID，逗号分隔\n\tNodeAttrContextFilter  = \"custom-sy-av-context-filter\" // 用于保存数据库块独有的上下文筛选配置\n\tNodeAttrViewStaticText = \"custom-sy-av-s-text\"         // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049\n\n\tNodeAttrViewNames = \"av-names\" // 用于临时标记块所属的属性视图名称，空格分隔","sourceCodeStart":1367,"sourceCodeEnd":1403,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/av.go#L1367-L1403","documentation":"Sentinel error ErrInvalidBoxID in kernel/av/av.go means the box (notebook) ID supplied when resolving an attribute view path is not a valid SiYuan node ID pattern. The library validates boxID with ast.IsNodeIDPattern before using it to locate the .sy file; an empty boxID is allowed (unscoped lookup), but a non-empty malformed one is rejected to prevent path/ID injection and futile file lookups.","triggerScenarios":"Calling parseAttributeViewByPathInBoxWithOptions (and its wrappers like writeAttributeViewData) with a boxID that is non-empty but fails ast.IsNodeIDPattern — e.g. a hand-crafted path segment, a URL-decoded garbage ID, or a truncated/typo'd notebook ID passed to an attribute-view API.","commonSituations":"Clients constructing avJSONPath manually instead of using the documented attribute view path; syncing stale plugin state where a notebook was deleted and the ID field holds a placeholder; tests exercising path validation (TestRejectInvalidAttributeViewPathIDs).","solutions":["Verify the boxID against ast.IsNodeIDPattern (or a 20/26-char node-ID regex) before passing it","Pass an empty string only when you intentionally want an unboxed lookup; otherwise obtain the box ID from a real notebook listing","Fix the caller that stores/propagates the box ID so it never persists a placeholder or partially truncated ID"],"exampleFix":"// before\n_, err := av.ParseAttributeViewByPathInBox(\"/data/\"+userPath+\".sy\", userPath)\n// after\nif boxID != \"\" && !ast.IsNodeIDPattern(boxID) {\n    return errors.New(\"invalid box id\")\n}\n_, err := av.ParseAttributeViewByPathInBox(avJSONPath, boxID)","handlingStrategy":"validation","validationCode":"if boxID != \"\" && !ast.IsNodeIDPattern(boxID) {\n    return fmt.Errorf(\"refusing call: invalid box id %q\", boxID)\n}","typeGuard":"func validBoxID(id string) bool { return id == \"\" || ast.IsNodeIDPattern(id) }","tryCatchPattern":null,"preventionTips":["Never hand-build attribute view paths; use returned paths from the API","Validate all persisted ids on load after upgrades","Treat empty boxID as a deliberate unscoped lookup only"],"tags":["validation","attribute-view","identifier"],"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"}