siyuan-note/siyuan · error

database history contains an invalid view

Error message

database history contains an invalid view

What it means

readBoundAttributeViewHistory walks every entry in the snapshot's Views array and rejects the file if any layout/view is nil. A nil view means the historical attribute view data is structurally corrupt — a view slot exists in the slice but holds no object. The kernel aborts the backup or restore operation rather than operating on a partially dereferenced view list that would cause nil-pointer panics later.

Solutions

  1. Remove or replace the malformed snapshot file at <historyDir>/<boxID>/storage/av/<avID>.json and choose another history version for the rollback
  2. Open the snapshot JSON and remove the null entries from the "views" array (or restore a valid full copy) if you must keep it
  3. Run data integrity checks / re-index the workspace to rule out broader corruption
  4. If corruption recurs, check disk health and sync tooling; avoid editing history files in place
Defensive patterns

Strategy: validation

Validate before calling

// Go: sanitize views before use
for _, layout := range view.Views {
    if layout == nil {
        return errors.New("snapshot contains a nil view")
    }
}

Type guard

if layout == nil {
    continue // or fail fast before dereferencing
}

Try / catch

view, err := readBoundAttributeViewHistory(file, boxID, avID)
if err != nil {
    if strings.Contains(err.Error(), "invalid view") {
        return ErrCorruptHistorySnapshot
    }
    return err
}

Prevention

When it happens

Trigger: RollbackDocHistory (via restoreBoundAttributeViewHistory), restoreEmbeddedAttributeViewHistory, or backupBoundAttributeViewHistory loads a historical storage/av/<avID>.json whose parsed Views slice contains a null entry — typically from corrupted, hand-edited, or truncated JSON history files.

Common situations: History files corrupted by disk issues or interrupted writes; manually edited snapshots where a view was removed but left as null; snapshot files moved between workspaces with mismatched versions; failed sync producing partial history data.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/attribute_view_block_history.go:60

	if view.ID != avID {
		return nil, errors.New("database history ID does not match its filename")
	}
	for _, kv := range view.KeyValues {
		if kv == nil || kv.Key == nil {
			return nil, errors.New("database history contains an invalid field")
		}
		for _, value := range kv.Values {
			if value == nil {
				return nil, errors.New("database history contains an invalid value")
			}
		}
	}
	if view.GetBlockKeyValues() == nil {
		return nil, errors.New("database history has no primary field")
	}
	for _, layout := range view.Views {
		if layout == nil {
			return nil, errors.New("database history contains an invalid view")
		}
		for _, group := range layout.Groups {
			if group == nil {
				return nil, errors.New("database history contains an invalid group")
			}
		}
	}
	return view, nil
}

// 内嵌数据库也先认证历史,并与绑定条目恢复一起纳入失败回滚。
func (tx *Transaction) restoreEmbeddedAttributeViewHistory(filename, boxID, avID string) error {
	historical, err := readBoundAttributeViewHistory(filename, boxID, avID)
	if err != nil {
		if boxID == "" && os.IsNotExist(err) {
			return nil
		}
		return err

View on GitHub (pinned to 9f775e8a12)