siyuan-note/siyuan · error
invalid document sort mode [%s]
Error message
invalid document sort mode [%s]
What it means
Setting the custom attribute that controls a document's sort mode (DocSortModeAttr) with a value that is not a valid integer or not one of the recognized sort modes. The kernel parses the attribute value with strconv.Atoi and re-validates it with IsValidDocSortMode; anything else is rejected so the document tree is never persisted with a corrupted ordering mode.
Source
Thrown at kernel/model/blockial.go:405
lowerName := strings.ToLower(name)
// 转换为小写再验证属性名
if !isValidAttrName(lowerName) {
err = errors.New(Conf.Language(25) + " [" + node.ID + "]")
return
}
if lowerName == "data-task" {
err = errors.New(`setting or removing [data-task] attribute is not allowed via this interface. Please use "/api/block/updateTaskListItemMarker" or "/api/block/batchUpdateTaskListItemMarker" to update the task list item marker`)
return
}
if DocSortModeAttr == lowerName {
if ast.NodeDocument != node.Type || IsBoxDoc(boxID, node.ID) {
err = fmt.Errorf("attribute [%s] is only supported on regular document roots", DocSortModeAttr)
return
}
if "" != value {
sortMode, parseErr := strconv.Atoi(value)
if nil != parseErr || !IsValidDocSortMode(sortMode) {
err = fmt.Errorf("invalid document sort mode [%s]", value)
return
}
value = strconv.Itoa(sortMode)
}
}
// 处理文档标签 https://github.com/siyuan-note/siyuan/issues/13311
if lowerName == "tags" {
var tags []string
tmp := strings.SplitSeq(value, ",")
for t := range tmp {
t = strings.TrimSpace(t)
if "" != t {
tags = append(tags, t)
}
}
tags = gulu.Str.RemoveDuplicatedElem(tags)
if 0 < len(tags) {View on GitHub (pinned to 8641553a1f)
Solutions
- Check the numeric value passed for the sort-mode attribute and use one of the valid codes accepted by IsValidDocSortMode (see kernel/model/blockial.go).
- Convert symbolic mode names to their integer codes before calling the set-attrs API.
- Inspect the node's attributes for stale values (e.g. from an older version) and clear or correct the attribute.
- Update plugin/automation code that constructs attribute payloads to validate the mode client-side before submission.
Example fix
// before attrs[DocSortModeAttr] = "name" setNodeAttrs(id, attrs) // after attrs[DocSortModeAttr] = strconv.Itoa(DocSortModeNameAsc) setNodeAttrs(id, attrs)
Defensive patterns
Strategy: validation
Validate before calling
function isValidDocSortModeValue(v string) bool {
n, err := strconv.Atoi(v)
return err == nil && model.IsValidDocSortMode(n)
} Prevention
- Always set the sort-mode attribute with numeric enum codes, never symbolic names
- Validate attribute values against IsValidDocSortMode before calling set-attrs APIs
- When copying attributes between nodes, re-validate derived/mode attributes
When it happens
Trigger: Calling BatchSetBlockAttrs, setNodeAttrs, or setNodeAttrsWithTx on a document root with the document-sort-mode attribute set to a non-numeric string (e.g. "asc", "name") or an integer outside the valid enum range. Also raised indirectly by attribute-view operations (doRemoveAttrViewView, freezeOtherAttrViewBlockVisibleViews, updateBoundBlockAvsAttribute) that propagate attributes to bound document roots.
Common situations: A plugin or script writes the sort-mode attribute directly via the API using a mode name instead of its numeric code; hand-edited .sy or attribute data containing an obsolete/unrecognized mode value; a version change that removed a formerly valid sort mode.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- The attribute name can only contain lowercase English letter
- --id is required
- --attr is required (format: name=value)
- invalid attr format [%s], expected name=value
- --ids is required
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/c0dee091efa4ba76.
Report an issue: GitHub.