siyuan-note/siyuan · error

invalid sort conf [ ]: expected an object

Error message

invalid sort conf [%s]: expected an object

What it means

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.

Solutions

  1. Open the conf file at the logged path and fix it to be a JSON object, e.g. {} or {"docID": 3}.
  2. If the content is unrecoverable, delete the file — the kernel will recreate defaults on next write.
  3. Restore the file from a backup or snapshot (SiYuan data repo snapshot).
  4. Validate the JSON with a linter after any manual edit and avoid editing it while the kernel is running.

Example fix

// before (sort conf file content)
null
// after
{
  "20240101120000-abcdefg": 3
}
Defensive patterns

Strategy: fallback

Validate before calling

// validate the conf file before the kernel reads it
const raw = JSON.parse(fs.readFileSync(confPath, "utf8") || "{}");
if (raw === null || Array.isArray(raw) || typeof raw !== "object") {
  fs.writeFileSync(confPath, "{}"); // repair to empty object
}

Type guard

function isSortConfObject(v) {
  return v !== null && typeof v === "object" && !Array.isArray(v) &&
    Object.values(v).every(x => typeof x === "number");
}

Try / catch

try {
  await someSortOperation();
} catch (e) {
  if (String(e).includes("invalid sort conf")) {
    // repair or delete the conf file named in the error, then retry once
    restoreOrResetSortConf(confPath);
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/f982e2a767e4f4d0. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/file.go:2471

	return title
}

func readSortConfMap(confPath string) (map[string]int, error) {
	if !filelock.IsExist(confPath) {
		return map[string]int{}, nil
	}
	data, err := filelock.ReadFile(confPath)
	if err != nil {
		logging.LogErrorf("read sort conf [%s] failed: %s", confPath, err)
		return nil, err
	}
	ret := map[string]int{}
	if err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {
		logging.LogWarnf("unmarshal sort conf [%s] failed: %s", confPath, err)
		return nil, err
	}
	if ret == nil {
		return nil, fmt.Errorf("invalid sort conf [%s]: expected an object", confPath)
	}
	return ret, nil
}

func writeSortConfMap(confPath string, fullSortIDs map[string]int) error {
	data, err := gulu.JSON.MarshalJSON(fullSortIDs)
	if err != nil {
		logging.LogErrorf("marshal sort conf [%s] failed: %s", confPath, err)
		return err
	}
	if err = filelock.WriteFile(confPath, data); err != nil {
		logging.LogErrorf("write sort conf [%s] failed: %s", confPath, err)
		return err
	}
	return nil
}

type DocSortModeResult struct {

View on GitHub (pinned to 9f775e8a12)