{"record":{"id":"1af11e9b460235fe","repo":"OtterMind/Chat2DB","slug":"datasource-not-found","errorCode":"datasource_not_found","errorMessage":"Datasource not found: ","messagePattern":"Datasource not found: ","errorType":"error_code","errorClass":"CliDomainException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/cli/CliDataSourceServiceImpl.java","lineNumber":141,"sourceCode":"\n    @Override\n    public CliDataSource update(CliDataSourceUpdateRequest request) {\n        WorkspaceDataSource dataSource = cliDataSourceConverter.update2storage(request);\n        workspaceStorageFacade.updateDataSource(dataSource);\n        dataSourceService.removeConnection(request.getDataSourceId());\n        return get(request.getDataSourceId());\n    }\n\n    @Override\n    public void delete(Long dataSourceId) {\n        requireDatasource(dataSourceId, workspaceStorageFacade.queryDataSourceById(dataSourceId, false));\n        workspaceStorageFacade.deleteDataSource(dataSourceId);\n        dataSourceService.removeConnection(dataSourceId);\n    }\n\n    private WorkspaceDataSource requireDatasource(Long dataSourceId, WorkspaceDataSource dataSource) {\n        if (dataSource == null) {\n            throw new CliDomainException(\"datasource_not_found\", \"Datasource not found: \" + dataSourceId);\n        }\n        return dataSource;\n    }\n\n    private void validateConnectionTestRequest(CliConnectionTestRequest request) {\n        boolean hasDatasourceId = request.getDataSourceId() != null;\n        boolean hasTemporaryField = StringUtils.isNotBlank(request.getDbType())\n                || StringUtils.isNotBlank(request.getUrl())\n                || StringUtils.isNotBlank(request.getHost())\n                || StringUtils.isNotBlank(request.getPort())\n                || StringUtils.isNotBlank(request.getDatabase())\n                || StringUtils.isNotBlank(request.getUser())\n                || request.getPassword() != null\n                || StringUtils.isNotBlank(request.getServiceName())\n                || StringUtils.isNotBlank(request.getServiceType());\n        if (hasDatasourceId) {\n            if (hasTemporaryField) {\n                throw new CliDomainException(\"invalid_connection_test_args\",","sourceCodeStart":123,"sourceCodeEnd":159,"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/cli/CliDataSourceServiceImpl.java#L123-L159","documentation":"CliDomainException code datasource_not_found thrown by requireDatasource when the storage lookup (workspaceStorageFacade.queryDataSourceById) returns null. Occurs on delete (and any path routing through requireDatasource) for a dataSourceId that does not exist in the workspace.","triggerScenarios":"DELETE datasource by an id that is absent, already deleted, or belongs to a different workspace/environment than the current context.","commonSituations":"Stale UI holding a deleted datasource id; the id was copied from another environment; race where the row was removed between list and delete.","solutions":["Re-fetch the datasource list (list_all_datasources) to obtain current valid ids.","Confirm the dataSourceId belongs to the active workspace/environment.","Treat not-found as idempotent success if the caller's intent is 'ensure deleted'."],"exampleFix":"// before\ndelete({ dataSourceId: 9999 }) // stale id\n\n// after\nconst ds = (await list_all_datasources()).find(d => d.alias === target);\nif (ds) delete({ dataSourceId: ds.id });","handlingStrategy":"try-catch","validationCode":"WorkspaceDataSource existing = workspaceStorageFacade.queryDataSourceById(dataSourceId, false);\nif (existing == null) {\n    // treat as already-deleted (idempotent) or refresh the list\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    cliDataSourceService.delete(dataSourceId);\n} catch (CliDomainException e) {\n    if (\"datasource_not_found\".equals(e.getCode())) {\n        return; // idempotent: already gone\n    }\n    throw e;\n}","preventionTips":["Refresh datasource ids from list before mutating.","Make delete handlers idempotent on not-found.","Avoid caching datasource ids long-term across sessions."],"tags":["datasource","not-found","cli","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}