siyuan-note/siyuan · error
ErrInvalidBoxID
ErrInvalidBoxID
Error message
invalid box id
What it means
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.
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
Example fix
// before
_, err := av.ParseAttributeViewByPathInBox("/data/"+userPath+".sy", userPath)
// after
if boxID != "" && !ast.IsNodeIDPattern(boxID) {
return errors.New("invalid box id")
}
_, err := av.ParseAttributeViewByPathInBox(avJSONPath, boxID) Defensive patterns
Strategy: validation
Validate before calling
if boxID != "" && !ast.IsNodeIDPattern(boxID) {
return fmt.Errorf("refusing call: invalid box id %q", boxID)
} Type guard
func validBoxID(id string) bool { return id == "" || ast.IsNodeIDPattern(id) } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- ErrInvalidAttributeViewID
- invalid attribute view ID
- invalid new item template id
- at least one visible view is required
- attribute view custom color index
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/ec7af382c45d42ab.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/av.go:1385
av := filepath.Join(util.DataDir, "storage", "av")
ret = filepath.Join(av, avID+".json")
if !gulu.File.IsDir(av) {
if err := os.MkdirAll(av, 0755); err != nil {
logging.LogErrorf("create attribute view dir failed: %s", err)
return
}
}
return
}
func GetAttributeViewI18n(key string) string {
return util.AttrViewLangs[util.Lang][key].(string)
}
var (
ErrAttributeViewNotFound = errors.New("attribute view not found")
ErrInvalidAttributeViewID = errors.New("invalid attribute view id")
ErrInvalidBoxID = errors.New("invalid box id")
ErrViewNotFound = errors.New("view not found")
ErrKeyNotFound = errors.New("key not found")
ErrItemNotFound = errors.New("item not found")
ErrWrongLayoutType = errors.New("wrong layout type")
ErrInvalidColumnAlign = errors.New("invalid column align")
ErrSpecTooNew = errors.New("attribute view spec is too new")
ErrRichTextSpecMismatch = errors.New("attribute view rich text requires storage spec 9")
ErrFilterTooDeep = errors.New("filter nesting depth exceeds the maximum allowed")
)
const (
NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id
NodeAttrView = "custom-sy-av-view" // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443
NodeAttrVisibleViewIDs = "custom-sy-av-visible-views" // 用于标记数据库块显示的视图 ID,逗号分隔
NodeAttrContextFilter = "custom-sy-av-context-filter" // 用于保存数据库块独有的上下文筛选配置
NodeAttrViewStaticText = "custom-sy-av-s-text" // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049
NodeAttrViewNames = "av-names" // 用于临时标记块所属的属性视图名称,空格分隔View on GitHub (pinned to 9f775e8a12)