{"record":{"id":"8b2537e9c6ebc1fe","repo":"nocobase/nocobase","slug":"datasource-datasourcekey-not-found-8b2537","errorCode":null,"errorMessage":"dataSource ${dataSourceKey} not found","messagePattern":"dataSource (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/data-sources-collections.ts","lineNumber":46,"sourceCode":"        if (error) {\n          throw new Error(`dataSource ${dataSourceKey} loading failed: ${error.message}`);\n        }\n\n        throw new Error(`dataSource ${dataSourceKey} loading failed`);\n      }\n\n      if (['loading', 'reloading'].includes(dataSourceStatus)) {\n        const progress = plugin.dataSourceLoadingProgress[dataSourceKey];\n\n        if (progress) {\n          throw new Error(`dataSource ${dataSourceKey} is ${dataSourceStatus} (${progress.loaded}/${progress.total})`);\n        }\n\n        throw new Error(`dataSource ${dataSourceKey} is ${dataSourceStatus}`);\n      }\n\n      if (!dataSource) {\n        throw new Error(`dataSource ${dataSourceKey} not found`);\n      }\n\n      const { paginate, filter = {} } = ctx.action.params;\n\n      const collections = lodash.sortBy(\n        dataSource.collectionManager.getCollections().filter((collection) => {\n          return filterMatch(collection.options, filter);\n        }),\n        'name',\n      );\n\n      const mapCollection = (collections) => {\n        return collections.map((collection) => {\n          return {\n            ...collection.options,\n            fields: collection.getFields().map((field) => field.options),\n          };\n        });","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/plugins/@nocobase/plugin-data-source-manager/src/server/resourcers/data-sources-collections.ts#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the dataSourceKey by listing data sources (dataSources:list) or checking the dataSources table, and correct the associatedIndex in the request.","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.","Re-create the missing data source in the Data Source Manager UI if it was deleted."],"exampleFix":"// before\nGET /api/dataSourcesCollections:list?associatedIndex=mysql-prod   // key does not exist\n// after\nGET /api/dataSources:list                                        // confirm real key, e.g. 'mysql_prod'\nGET /api/dataSourcesCollections:list?associatedIndex=mysql_prod","handlingStrategy":"validation","validationCode":"const keys = new Set((await api.resource('dataSources').list({ paginate: false })).data.data.map((ds) => ds.key));\nif (!keys.has(dataSourceKey)) {\n  throw new Error(`Unknown dataSourceKey '${dataSourceKey}'. Available: ${[...keys].join(', ')}`);\n}","typeGuard":"function dataSourceExists(app: any, key: string): boolean {\n  return typeof key === 'string' && key.length > 0 && app.dataSourceManager.dataSources.has(key);\n}","tryCatchPattern":"try {\n  return await api.resource('dataSourcesCollections').list({ associatedIndex: key });\n} catch (e) {\n  if (/not found$/.test(e.message) && e.message.includes('dataSource')) {\n    throw new Error(`Data source '${key}' is not registered — check Data Source Manager configuration`, { cause: e });\n  }\n  throw e;\n}","preventionTips":["Store data source keys in shared config/constants, never hardcode ad-hoc strings.","List registered data sources when wiring up a new integration to confirm the exact key.","After deleting or disabling a data source, purge dependent client pages/scripts.","Remember associatedIndex takes the dataSourceKey, not the collection name."],"tags":["data-source","not-found","configuration","nocobase"],"backgroundTag":"resource-not-found","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}