siyuan-note/siyuan · warning

invalid sort conf [%s]: expected an object

Error message

invalid sort conf [%s]: expected an object

What it means

readSortConfMap unmarshals the per-notebook sort configuration file (.siyuan/sort.json or similar) into map[string]int; if JSON decoding yields a nil map (e.g. the file contains 'null' or a non-object like an array/string), the kernel returns fmt.Errorf("invalid sort conf [%s]: expected an object", confPath). The message embeds the offending config file path.

Source

Thrown at kernel/model/file.go:2452

	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 8641553a1f)

Solutions

  1. Delete or fix the corrupted sort conf file (path is shown in the error) so the kernel regenerates it
  2. Replace the file content with a valid JSON object, e.g. {"20230801...": 0}
  3. Restore the file from a backup or via sync history
  4. Re-sync the workspace if the corruption came from a conflicted sync merge
Defensive patterns

Strategy: fallback

Validate before calling

// validate the sort conf file content before the kernel reads it
function isValidSortConf(raw) {
  const v = JSON.parse(raw);
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Type guard

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

Try / catch

try {
  const conf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
  if (!isSortConfObject(conf)) fs.unlinkSync(confPath); // let kernel regenerate
} catch (e) {
  fs.unlinkSync(confPath);
}

Prevention

When it happens

Trigger: Any operation that loads doc sort configuration (listing files in a notebook, SetDocSortMode, sort reads) after sort conf was written as null, corrupted, or replaced by a non-object JSON value on disk.

Common situations: Manual editing of the sort conf file; a crashed write leaving 'null'; sync tools merging the file into a JSON array; older versions writing a different shape that no longer unmarshals into map[string]int.

Related errors


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