siyuan-note/siyuan · error
notebook sort item must not be nil
Error message
notebook sort item must not be nil
What it means
When planning a notebook sort, each entry in the notebookSorts request list must be a non-nil item. A nil entry means the request payload contained a null element in the sort array; the validation aborts with errors.New("notebook sort item must not be nil") before any change is persisted. It is a defensive request-shape check.
Solutions
- Remove null entries from the notebookSorts array before sending the request
- In client code, filter or initialize all slice elements before marshaling to JSON
- Validate the request payload shape against the API schema before submission
Example fix
// before: nil holes in Go client
items := make([]*SortItem, 3)
items[0] = &SortItem{ID: "202401..."}
sortNotebooks(items)
// after
items := make([]*SortItem, 0, 3)
for _, it := range rawItems {
if it != nil {
items = append(items, it)
}
}
sortNotebooks(items) Defensive patterns
Strategy: validation
Validate before calling
if (notebookSorts.some(i => i == null)) throw new Error('notebookSorts contains null entries'); Type guard
const isSortItem = (i) => i != null && typeof i.id === 'string' && i.id.length > 0;
Try / catch
try { await api.sortNotebooks(notebookSorts); } catch (e) { if (String(e).includes('must not be nil')) { await api.sortNotebooks(notebookSorts.filter(Boolean)); } else { throw e; } } Prevention
- Filter null/undefined from arrays before JSON serialization
- Use push instead of index assignment when building sort lists
- Validate payloads against the API schema in tests
When it happens
Trigger: POSTing the sort API with a JSON body like {"notebookSorts":[null]} or [null,{...}] — usually produced by programmatic clients, plugins, or scripting that builds the array with unassigned slots.
Common situations: Plugin/script allocating a slice with make([]*Item, n) and leaving holes; JSON deserialization producing null for undefined entries; template-driven request generation with optional entries left empty.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/adeb179a185d798d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/file.go:2909
}
FlushTxQueue()
fileTreeSortLock.Lock()
defer fileTreeSortLock.Unlock()
boxes := map[string]*Box{}
for _, box := range Conf.GetBoxes() {
boxes[box.ID] = box
}
openedBoxes := map[string]*Box{}
for _, box := range Conf.GetOpenedBoxes() {
openedBoxes[box.ID] = box
}
notebookPlans := make([]*notebookSortPlan, 0, len(notebookSorts))
notebookIDs := map[string]struct{}{}
for _, item := range notebookSorts {
if nil == item {
return ret, errors.New("notebook sort item must not be nil")
}
if _, ok := notebookIDs[item.ID]; ok {
return ret, fmt.Errorf("duplicate notebook ID [%s]", item.ID)
}
notebookIDs[item.ID] = struct{}{}
box := boxes[item.ID]
if nil == box {
return ret, fmt.Errorf("notebook [%s] not found", item.ID)
}
notebookPlans = append(notebookPlans, ¬ebookSortPlan{item: item, box: box})
}
docPlans := make([]*docSortPlan, 0, len(docSorts))
docIDs := map[string]struct{}{}
for _, item := range docSorts {
if nil == item {
return ret, errors.New("document sort item must not be nil")View on GitHub (pinned to 9f775e8a12)