{"record":{"id":"c0dee091efa4ba76","repo":"siyuan-note/siyuan","slug":"invalid-document-sort-mode-s","errorCode":null,"errorMessage":"invalid document sort mode [%s]","messagePattern":"invalid document sort mode \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/blockial.go","lineNumber":405,"sourceCode":"\t\tlowerName := strings.ToLower(name)\n\t\t// 转换为小写再验证属性名\n\t\tif !isValidAttrName(lowerName) {\n\t\t\terr = errors.New(Conf.Language(25) + \" [\" + node.ID + \"]\")\n\t\t\treturn\n\t\t}\n\t\tif lowerName == \"data-task\" {\n\t\t\terr = 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`)\n\t\t\treturn\n\t\t}\n\t\tif DocSortModeAttr == lowerName {\n\t\t\tif ast.NodeDocument != node.Type || IsBoxDoc(boxID, node.ID) {\n\t\t\t\terr = fmt.Errorf(\"attribute [%s] is only supported on regular document roots\", DocSortModeAttr)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif \"\" != value {\n\t\t\t\tsortMode, parseErr := strconv.Atoi(value)\n\t\t\t\tif nil != parseErr || !IsValidDocSortMode(sortMode) {\n\t\t\t\t\terr = fmt.Errorf(\"invalid document sort mode [%s]\", value)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tvalue = strconv.Itoa(sortMode)\n\t\t\t}\n\t\t}\n\n\t\t// 处理文档标签 https://github.com/siyuan-note/siyuan/issues/13311\n\t\tif lowerName == \"tags\" {\n\t\t\tvar tags []string\n\t\t\ttmp := strings.SplitSeq(value, \",\")\n\t\t\tfor t := range tmp {\n\t\t\t\tt = strings.TrimSpace(t)\n\t\t\t\tif \"\" != t {\n\t\t\t\t\ttags = append(tags, t)\n\t\t\t\t}\n\t\t\t}\n\t\t\ttags = gulu.Str.RemoveDuplicatedElem(tags)\n\t\t\tif 0 < len(tags) {","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/blockial.go#L387-L423","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nattrs[DocSortModeAttr] = \"name\"\nsetNodeAttrs(id, attrs)\n// after\nattrs[DocSortModeAttr] = strconv.Itoa(DocSortModeNameAsc)\nsetNodeAttrs(id, attrs)","handlingStrategy":"validation","validationCode":"function isValidDocSortModeValue(v string) bool {\n    n, err := strconv.Atoi(v)\n    return err == nil && model.IsValidDocSortMode(n)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["validation","sort-mode","attributes"],"backgroundTag":"invalid-enum-value","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}