siyuan-note/siyuan · error
ErrInvalidID
ErrInvalidID
Error message
invalid id
What it means
ErrInvalidID is the sentinel error for an ID that does not match the required node-ID pattern (ast.IsNodeIDPattern: timestamp-random alphanumeric form). Attribute-view rendering and repo-snapshot AV resolution return it before doing any I/O when the supplied avID is structurally invalid.
Source
Thrown at kernel/model/tree.go:216
if err = treenode.CheckSpecJSON(data); nil != err {
return
}
ret, err = dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
if err != nil {
logging.LogErrorf("parse json to tree [%s] failed: %s", localPath, err)
return
}
return
}
var (
ErrBoxNotFound = errors.New("notebook not found")
ErrBoxClosed = errors.New("notebook closed")
ErrBlockNotFound = errors.New("block not found")
ErrTreeNotFound = errors.New("tree not found")
ErrIndexing = errors.New("indexing")
ErrBoxUnindexed = errors.New("notebook unindexed")
ErrInvalidID = errors.New("invalid id")
)
func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
return LoadTreeByBlockIDWithReindexInBox(id, "")
}
// LoadTreeByBlockIDWithReindexInBox 与 LoadTreeByBlockIDWithReindex 一致,但按 boxID 路由 blocktree 查询。
func LoadTreeByBlockIDWithReindexInBox(id, boxID string) (ret *parse.Tree, err error) {
if "" == id {
logging.LogWarnf("block id is empty")
return nil, ErrTreeNotFound
}
bt := treenode.GetBlockTreeInBox(id, boxID)
if nil == bt && "" == boxID {
// boxID 未知时(如通用打开入口),遍历所有已打开的加密笔记本查找
for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {View on GitHub (pinned to 8641553a1f)
Solutions
- Validate the avID with ast.IsNodeIDPattern (or the same regex) before calling; ensure it is the av block's node ID, not its name
- Fetch the correct av ID from the document tree (the attribute-view node's ID) or via SQL from the blocks table
- Correct corrupted snapshot/template metadata if the stored avID itself is malformed
Example fix
// before
RenderAttributeView(avID, viewID, ...)
// after
if !ast.IsNodeIDPattern(avID) {
return fmt.Errorf("invalid av id: %q", avID)
}
RenderAttributeView(avID, viewID, ...) Defensive patterns
Strategy: validation
Validate before calling
if !ast.IsNodeIDPattern(avID) {
return fmt.Errorf("invalid av id: %q", avID)
} Type guard
func isValidNodeID(id string) bool { return ast.IsNodeIDPattern(id) } Try / catch
if errors.Is(err, model.ErrInvalidID) {
return fmt.Errorf("check the av ID: %w", err)
} Prevention
- Pass the attribute-view node's ID, never its display name
- Copy IDs programmatically rather than by hand from logs
- Validate IDs with ast.IsNodeIDPattern before any model call
When it happens
Trigger: RenderAttributeViewWithTarget called with an avID that is not a valid node ID (e.g. an empty string, a view name, or a user-typed identifier); ResolveRepoSnapshotAttributeViewBoxID invoked with a malformed avID from snapshot metadata.
Common situations: Plugins passing an attribute-view *name* or database config key instead of the av ID; hand-edited templates or snapshots with corrupted IDs; truncated IDs from logs or user copy-paste.
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
- wrong layout type
- filter nesting depth exceeds the maximum allowed
- invalid session id
- invalid session data
- new item template name is empty
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/be6cc0978e6d2084.
Report an issue: GitHub.