{"record":{"id":"f664287411dda0f3","repo":"OtterMind/Chat2DB","slug":"datasource-not-found-f66428","errorCode":"datasource.not.found","errorMessage":"datasource.not.found","messagePattern":"datasource\\.not\\.found","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbConnectionContextServiceImpl.java","lineNumber":195,"sourceCode":"        List<ai.chat2db.community.domain.api.model.metadata.Table> tables;\n        if (ObjectTypeEnum.VIEW.name().equalsIgnoreCase(objectType)) {\n            tables = metaData.views(Chat2DBContext.getConnection(),\n                    new ViewMetadataRequest(databaseName, schemaName, objectName));\n        } else {\n            tables = metaData.tables(Chat2DBContext.getConnection(),\n                    new TablesRequest(databaseName, schemaName, objectName));\n        }\n        if (tables == null) {\n            return Collections.emptyList();\n        }\n        return tables.stream().filter(Objects::nonNull).toList();\n    }\n\n    private ConnectInfo buildConnectInfo(DbConnectionContextRequest param) {\n        WorkspaceDataSource dataSource = workspaceDataSourceService.queryDisplayDataSourceById(param.getDataSourceId(), true);\n        if (dataSource == null) {\n            log.info(\"query datasource failed:{}\", param.getDataSourceId());\n            throw new BusinessException(\"datasource.not.found\");\n        }\n        return connectionContextConverter.datasource2connectInfo(param, dataSource, dataSource.getUrl());\n    }\n\n    private ConnectInfo buildMcpConnectInfo(McpConnectionContextRequest param) {\n        return connectionContextConverter.mcpParam2connectInfo(param, connectionContextConverter.buildMcpDataSourceId(param));\n    }\n\n}\n","sourceCodeStart":177,"sourceCodeEnd":205,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbConnectionContextServiceImpl.java#L177-L205","documentation":"Thrown by buildConnectInfo() when workspaceDataSourceService.queryDisplayDataSourceById(dataSourceId, true) returns null — the requested data source does not exist or is not visible to the current user. There is no i18n entry for 'datasource.not.found', so the raw key is shown.","triggerScenarios":"DbConnectionContextServiceImpl.connect(param) is called with a dataSourceId that has no matching row in the workspace data source store (deleted, wrong ID, permission/visibility filtered out).","commonSituations":"Stale datasource ID cached on the frontend after the datasource was deleted, a mistyped/forbidden ID, or a multi-tenant visibility filter hiding the row.","solutions":["Verify the dataSourceId exists and is visible to the user before attempting to connect.","If deleted, clear the stale reference on the client and force a datasource-list refresh.","Add an i18n entry for 'datasource.not.found' so users see a localized 'Data source not found' message."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before connecting\nWorkspaceDataSource ds = workspaceDataSourceService.queryDisplayDataSourceById(dataSourceId, true);\nif (ds == null) {\n    return Result.fail(\"datasource.not.found\"); // or a localized message\n}\ndbConnectionContextService.connect(param);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the datasource ID exists and is visible to the user before connecting.","Refresh the datasource list on the client when an ID becomes stale after deletion.","Add an i18n entry for 'datasource.not.found' so users see a localized message."],"tags":["datasource","not-found","i18n","connection"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}