toeverything/AFFiNE · error · BlockSuiteError

DatabaseBlockError

DatabaseBlockError

Error message

Unknown view type: ${type}

What it means

Thrown by DatabaseBlockDataSource.viewMetaGet(type) when the supplied view type string is not a key in databaseBlockViewMap. That map is built from viewPresets.tableViewMeta, kanbanViewMeta, and calendarViewMeta, so only their 'type' values are valid. The error code is DatabaseBlockError and is used whenever a view mode is resolved (e.g. viewMetaGetById resolves a view's mode through this method).

Source

Thrown at blocksuite/affine/blocks/database/src/data-source.ts:606

  viewDataGet(viewId: string): DataViewDataType | undefined {
    return this.viewDataList$.value.find(data => data.id === viewId)!;
  }

  viewDataMoveTo(id: string, position: InsertToPosition): void {
    moveViewTo(this._model, id, position);
  }

  viewDataUpdate<ViewData extends DataViewDataType>(
    id: string,
    updater: (data: ViewData) => Partial<ViewData>
  ): void {
    updateView(this._model, id, updater);
  }

  viewMetaGet(type: string): ViewMeta {
    const view = databaseBlockViewMap[type];
    if (!view) {
      throw new BlockSuiteError(
        ErrorCode.DatabaseBlockError,
        `Unknown view type: ${type}`
      );
    }
    return view;
  }

  viewMetaGetById(viewId: string): ViewMeta | undefined {
    const view = this.viewDataGet(viewId);
    if (!view) {
      return;
    }
    return this.viewMetaGet(view.mode);
  }
}

export const databaseViewInitTemplate = (
  datasource: DatabaseBlockDataSource,

View on GitHub (pinned to 26c515e050)

Solutions

  1. Register the custom view preset in databaseBlockViews (database/src/views/index.ts) so its type is present in databaseBlockViewMap.
  2. Validate the view mode against the registered types before calling viewMetaGet; fall back to a known type (e.g. 'table') for unknown modes.
  3. On version mismatch, run a migration that maps or removes unknown view modes from the block's views array.

Example fix

// before
datasource.viewMetaGet(unknownMode); // throws DatabaseBlockError

// after
const knownTypes = Object.keys(databaseBlockViewMap);
const mode = knownTypes.includes(storedMode) ? storedMode : 'table';
const meta = datasource.viewMetaGet(mode);
Defensive patterns

Strategy: validation

Validate before calling

import { databaseBlockViewMap } from '@blocksuite/affine-block-database';
const known = Object.keys(databaseBlockViewMap);
const mode = known.includes(storedMode) ? storedMode : 'table';
datasource.viewMetaGet(mode);

Type guard

import { databaseBlockViewMap } from '@blocksuite/affine-block-database';
function isKnownViewType(type: string): boolean {
  return type in databaseBlockViewMap;
}

Prevention

When it happens

Trigger: Calling viewMetaGet(type) or viewMetaGetById(viewId) (which internally calls viewMetaGet(view.mode)) where type/view.mode is not 'table', 'kanban', or 'calendar'. Persisting or injecting a DataViewDataType with an unknown mode. Loading a doc whose database block view was created by a newer/older version with a view preset not registered here.

Common situations: Version skew: a doc saved by a version that registered an extra view preset (e.g. a gallery/timeline view) opened in a build that lacks it. Custom view presets added without being appended to databaseBlockViews. Programmatic snapshot injection with a fabricated mode string.

Related errors


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/6fe1a7328a8c3fa4. Report an issue: GitHub.