{"record":{"id":"f982e2a767e4f4d0","repo":"siyuan-note/siyuan","slug":"invalid-sort-conf-s-expected-an-object","errorCode":null,"errorMessage":"invalid sort conf [%s]: expected an object","messagePattern":"invalid sort conf \\[(.+?)\\]: expected an object","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2471,"sourceCode":"\treturn title\n}\n\nfunc readSortConfMap(confPath string) (map[string]int, error) {\n\tif !filelock.IsExist(confPath) {\n\t\treturn map[string]int{}, nil\n\t}\n\tdata, err := filelock.ReadFile(confPath)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"read sort conf [%s] failed: %s\", confPath, err)\n\t\treturn nil, err\n\t}\n\tret := map[string]int{}\n\tif err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {\n\t\tlogging.LogWarnf(\"unmarshal sort conf [%s] failed: %s\", confPath, err)\n\t\treturn nil, err\n\t}\n\tif ret == nil {\n\t\treturn nil, fmt.Errorf(\"invalid sort conf [%s]: expected an object\", confPath)\n\t}\n\treturn ret, nil\n}\n\nfunc writeSortConfMap(confPath string, fullSortIDs map[string]int) error {\n\tdata, err := gulu.JSON.MarshalJSON(fullSortIDs)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"marshal sort conf [%s] failed: %s\", confPath, err)\n\t\treturn err\n\t}\n\tif err = filelock.WriteFile(confPath, data); err != nil {\n\t\tlogging.LogErrorf(\"write sort conf [%s] failed: %s\", confPath, err)\n\t\treturn err\n\t}\n\treturn nil\n}\n\ntype DocSortModeResult struct {","sourceCodeStart":2453,"sourceCodeEnd":2489,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2453-L2489","documentation":"readSortConfMap loads a per-notebook/filetree sort-configuration JSON file, unmarshals it into map[string]int, and if the JSON decoded into a nil map (file contains 'null', '[]', or an empty file parsed as null) it returns fmt.Errorf(\"invalid sort conf [%s]: expected an object\", confPath). The kernel expects the conf file to be a JSON object mapping doc IDs to sort-mode integers.","triggerScenarios":"The sort conf file at the given confPath contains literal null, an empty file, or a JSON array instead of an object; the file was truncated or hand-edited; an older/other tool wrote an incompatible shape.","commonSituations":"Manual editing of workspace data files breaking the JSON shape; a crash mid-write leaving a 0-byte or partial file; syncing conf files between versions with different formats; copying files between workspaces incorrectly.","solutions":["Open the conf file at the logged path and fix it to be a JSON object, e.g. {} or {\"docID\": 3}.","If the content is unrecoverable, delete the file — the kernel will recreate defaults on next write.","Restore the file from a backup or snapshot (SiYuan data repo snapshot).","Validate the JSON with a linter after any manual edit and avoid editing it while the kernel is running."],"exampleFix":"// before (sort conf file content)\nnull\n// after\n{\n  \"20240101120000-abcdefg\": 3\n}","handlingStrategy":"fallback","validationCode":"// validate the conf file before the kernel reads it\nconst raw = JSON.parse(fs.readFileSync(confPath, \"utf8\") || \"{}\");\nif (raw === null || Array.isArray(raw) || typeof raw !== \"object\") {\n  fs.writeFileSync(confPath, \"{}\"); // repair to empty object\n}","typeGuard":"function isSortConfObject(v) {\n  return v !== null && typeof v === \"object\" && !Array.isArray(v) &&\n    Object.values(v).every(x => typeof x === \"number\");\n}","tryCatchPattern":"try {\n  await someSortOperation();\n} catch (e) {\n  if (String(e).includes(\"invalid sort conf\")) {\n    // repair or delete the conf file named in the error, then retry once\n    restoreOrResetSortConf(confPath);\n  } else { throw e; }\n}","preventionTips":["Do not hand-edit kernel-managed conf JSON files while the kernel runs.","After any manual edit, ensure the file is a JSON object, never null/array.","Restore corrupted conf files from snapshots instead of leaving them empty."],"tags":["kernel","sort-config","json","corrupt-config"],"backgroundTag":"invalid-config-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}