siyuan-note/siyuan · error

unsupported view state version

Error message

unsupported view state version %d

What it means

getViewStateStorage reads storage/view-state.json and checks the header's version field against the kernel's supported viewStateVersion (currently 1). If the on-disk file was written by a NEWER kernel with a higher version, loading is refused with this error rather than misinterpreting unknown fields. Lower versions load fine (forward compatible only).

Solutions

  1. Upgrade the kernel to the version that wrote the file (match the version that produced view-state.json)
  2. Remove or archive data/storage/view-state.json to reset view state to empty (loses stored view states)
  3. Restore a backup of view-state.json written by a compatible version
Defensive patterns

Strategy: try-catch

Validate before calling

// check the on-disk version before loading
data, _ := os.ReadFile(filepath.Join(dataDir, "storage", "view-state.json"))
var header struct{ Version int `json:"version"` }
if json.Unmarshal(data, &header) == nil && header.Version > 1 {
    // kernel too old: upgrade before touching view state
}

Try / catch

if _, err := GetViewState(key); err != nil && strings.HasPrefix(err.Error(), "unsupported view state version") {
    // stop using/overwriting view-state.json; upgrade the kernel or restore a compatible backup
}

Prevention

When it happens

Trigger: Downgrading SiYuan (or opening a workspace) with an older kernel after a newer version already wrote view-state.json with version > 1; a workspace shared between installations of different builds.

Common situations: Rolling back to a previous release; syncing a workspace between machines running different kernel versions; test/dev builds writing a bumped version constant.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/view_state.go:320

	}
	dataPath := filepath.Join(util.DataDir, "storage", "view-state.json")
	if !filelock.IsExist(dataPath) {
		return
	}

	data, err := filelock.ReadFile(dataPath)
	if err != nil {
		logging.LogErrorf("read storage [view-state] failed: %s", err)
		return nil, err
	}
	header := struct {
		Version int `json:"version"`
	}{}
	if err = gulu.JSON.UnmarshalJSON(data, &header); err != nil {
		return backupCorruptedViewState(dataPath, err)
	}
	if viewStateVersion < header.Version {
		return nil, fmt.Errorf("unsupported view state version %d", header.Version)
	}
	if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
		return backupCorruptedViewState(dataPath, err)
	}
	if nil == ret.Views {
		ret.Views = map[string]*ViewState{}
	}
	for key, state := range ret.Views {
		if nil == state {
			delete(ret.Views, key)
			continue
		}
		if nil == state.Data {
			state.Data = map[string]any{}
		}
	}
	pruneViewStates(ret.Views)
	for _, state := range ret.Views {

View on GitHub (pinned to 9f775e8a12)