siyuan-note/siyuan · error
invalid block structure: block node is nil
Error message
invalid block structure: block node is nil
What it means
invalidBlockNodeError returns this message when the node handed to the block structure validator is nil. Since a nil AST node has no type or ID, the validator cannot classify it and reports a nil block node explicitly. It is thrown by ValidateBlockSubtree, ValidateBlockPlacement, and ValidateBlockReplacement as the first guard.
Solutions
- Verify the block ID exists before validating (e.g. via a query of the blocks table)
- Re-fetch the tree/node after any delete/rename operation; handle the not-found case instead of forwarding nil
- Check that the tree was parsed successfully before operating on its nodes
Example fix
// before
node := tree.FindByID(id)
return treenode.ValidateBlockPlacement(node, child) // node may be nil
// after
node := tree.FindByID(id)
if node == nil {
return fmt.Errorf("block %s not found", id)
}
return treenode.ValidateBlockPlacement(node, child) Defensive patterns
Strategy: type-guard
Validate before calling
const info = await getBlockInfo(id);
if (!info) throw new Error("block not found: " + id); Type guard
function nodeExists(n) { return n != null && typeof n.ID === "string" && n.ID.length > 0; } Try / catch
try { treenode.ValidateBlockPlacement(node, child); } catch (e) { if (String(e.message).includes("block node is nil")) reFetchTree(); else throw e; } Prevention
- Check that IDs resolve before calling validation/insert APIs
- Re-fetch nodes after delete/sync operations
- Never forward a nil node from a failed lookup; fail fast with your own clear error
When it happens
Trigger: Calling validation/insert/replace APIs with a node reference that failed lookup — e.g. an ID that does not exist, a tree that was not loaded, or passing nil explicitly after a failed query in calling code.
Common situations: Plugin code that assumes a block ID exists without checking; racing deletes where the node is removed between lookup and validation; parse failures leaving the node nil.
Related errors
- attribute view custom color must not be null
- block [ ] is not a document that can declare a child…
- configuration must not be null
- document [ ] cannot be pinned
- Field [ ] must not be null
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/d1605a058b9693e4.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/treenode/block_structure.go:242
item.ListData.Num = num
item.ListData.Delimiter = delimiter
item.ListData.Marker = []byte(strconv.Itoa(num) + string(delimiter))
num++
}
}
func isContentBlock(node *ast.Node) bool {
return nil != node && node.IsBlock() && ast.NodeKramdownBlockIAL != node.Type
}
func invalidBlockContainmentError(parent, child *ast.Node) error {
return fmt.Errorf("invalid block structure: %s [%s] cannot contain %s [%s]",
parent.Type.String(), parent.ID, child.Type.String(), child.ID)
}
func invalidBlockNodeError(node *ast.Node) error {
if nil == node {
return fmt.Errorf("invalid block structure: block node is nil")
}
return fmt.Errorf("invalid block structure: %s [%s] is not a content block", node.Type.String(), node.ID)
}
View on GitHub (pinned to 9f775e8a12)