nocobase/nocobase · error

dataSource ${dataSourceKey} not found

Error message

dataSource ${dataSourceKey} not found

What it means

Thrown by the dataSources.collections:list action when the dataSourceKey taken from the request's associatedIndex does not exist in ctx.app.dataSourceManager.dataSources. This fires only after the loading-state checks pass, meaning the data source is not loading but is simply not registered at all — a wrong key, an unloaded plugin, or a source that failed to register.

Source

Thrown at packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/data-sources-collections.ts:46

        if (error) {
          throw new Error(`dataSource ${dataSourceKey} loading failed: ${error.message}`);
        }

        throw new Error(`dataSource ${dataSourceKey} loading failed`);
      }

      if (['loading', 'reloading'].includes(dataSourceStatus)) {
        const progress = plugin.dataSourceLoadingProgress[dataSourceKey];

        if (progress) {
          throw new Error(`dataSource ${dataSourceKey} is ${dataSourceStatus} (${progress.loaded}/${progress.total})`);
        }

        throw new Error(`dataSource ${dataSourceKey} is ${dataSourceStatus}`);
      }

      if (!dataSource) {
        throw new Error(`dataSource ${dataSourceKey} not found`);
      }

      const { paginate, filter = {} } = ctx.action.params;

      const collections = lodash.sortBy(
        dataSource.collectionManager.getCollections().filter((collection) => {
          return filterMatch(collection.options, filter);
        }),
        'name',
      );

      const mapCollection = (collections) => {
        return collections.map((collection) => {
          return {
            ...collection.options,
            fields: collection.getFields().map((field) => field.options),
          };
        });

View on GitHub (pinned to fa42722fef)

Solutions

  1. Verify the dataSourceKey by listing data sources (dataSources:list) or checking the dataSources table, and correct the associatedIndex in the request.
  2. If the source should exist, ensure the data-source-manager plugin and the driver plugin for that source are installed and enabled, then restart/reload.
  3. Re-create the missing data source in the Data Source Manager UI if it was deleted.

Example fix

// before
GET /api/dataSourcesCollections:list?associatedIndex=mysql-prod   // key does not exist
// after
GET /api/dataSources:list                                        // confirm real key, e.g. 'mysql_prod'
GET /api/dataSourcesCollections:list?associatedIndex=mysql_prod
Defensive patterns

Strategy: validation

Validate before calling

const keys = new Set((await api.resource('dataSources').list({ paginate: false })).data.data.map((ds) => ds.key));
if (!keys.has(dataSourceKey)) {
  throw new Error(`Unknown dataSourceKey '${dataSourceKey}'. Available: ${[...keys].join(', ')}`);
}

Type guard

function dataSourceExists(app: any, key: string): boolean {
  return typeof key === 'string' && key.length > 0 && app.dataSourceManager.dataSources.has(key);
}

Try / catch

try {
  return await api.resource('dataSourcesCollections').list({ associatedIndex: key });
} catch (e) {
  if (/not found$/.test(e.message) && e.message.includes('dataSource')) {
    throw new Error(`Data source '${key}' is not registered — check Data Source Manager configuration`, { cause: e });
  }
  throw e;
}

Prevention

When it happens

Trigger: GET /api/dataSourcesCollections:list (or ctx.app.pm dataSources.collections:list action) with an associatedIndex that matches no registered data source key, e.g. 'mysql2' when only 'main' exists, or a source whose plugin failed to install/activate.

Common situations: Typo in the data source key in a URL or client configuration; referencing a data source created in another environment; data source removed from the dataSources collection while cached client pages still reference it; using the collection name instead of the data source key as associatedIndex.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of nocobase/nocobase@fa42722fef (2026-09-01). Data as JSON: /api/errors/8b2537e9c6ebc1fe. Report an issue: GitHub.