siyuan-note/siyuan · error

block [%s] is not a document that can declare a child docume

Error message

block [%s] is not a document that can declare a child document sort mode

What it means

SetDocSortMode guard: the block ID resolved to a tree, but the block is not the document root (tree.ID != id or the node is not NodeDocument). Only a document can declare a child-document sort mode; passing a child block's ID triggers this error.

Source

Thrown at kernel/model/file.go:2490

	ID                string `json:"id"`
	Path              string `json:"path"`
	SortMode          *int   `json:"sortMode"`
	EffectiveSortMode int    `json:"effectiveSortMode"`
}

// SetDocSortMode 设置文档对子文档列表声明的排序方式,sortMode 为 nil 时恢复继承。
func SetDocSortMode(id string, sortMode *int) (ret *DocSortModeResult, err error) {
	if nil != sortMode && !IsValidDocSortMode(*sortMode) {
		return nil, fmt.Errorf("invalid document sort mode [%d]", *sortMode)
	}

	FlushTxQueue()
	tree, err := LoadTreeByBlockID(id)
	if nil != err {
		return nil, err
	}
	if tree.ID != id || tree.Root.ID != id || ast.NodeDocument != tree.Root.Type || IsBoxDoc(tree.Box, tree.ID) {
		return nil, fmt.Errorf("block [%s] is not a document that can declare a child document sort mode", id)
	}

	value := ""
	if nil != sortMode {
		value = strconv.Itoa(*sortMode)
	}
	if tree.Root.IALAttr(DocSortModeAttr) != value {
		if err = setNodeAttrs(tree.Root, tree, map[string]string{DocSortModeAttr: value}); nil != err {
			return nil, err
		}
	}

	effectiveSortMode, resolveErr := ResolveDocTreeSortMode(tree.Box, tree.Path)
	if nil != resolveErr {
		return nil, resolveErr
	}
	ret = &DocSortModeResult{
		Box:               tree.Box,

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Pass the document ID (root block ID), not a child block ID
  2. Obtain the root ID via the block tree before calling
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at kernel/model/file.go:2490 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/38f990aff4837613. Report an issue: GitHub.