OtterMind/Chat2DB · error · CliDomainException
datasource_not_found
datasource_not_found
Error message
Datasource not found:
What it means
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.
Source
Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/cli/CliDataSourceServiceImpl.java:141
@Override
public CliDataSource update(CliDataSourceUpdateRequest request) {
WorkspaceDataSource dataSource = cliDataSourceConverter.update2storage(request);
workspaceStorageFacade.updateDataSource(dataSource);
dataSourceService.removeConnection(request.getDataSourceId());
return get(request.getDataSourceId());
}
@Override
public void delete(Long dataSourceId) {
requireDatasource(dataSourceId, workspaceStorageFacade.queryDataSourceById(dataSourceId, false));
workspaceStorageFacade.deleteDataSource(dataSourceId);
dataSourceService.removeConnection(dataSourceId);
}
private WorkspaceDataSource requireDatasource(Long dataSourceId, WorkspaceDataSource dataSource) {
if (dataSource == null) {
throw new CliDomainException("datasource_not_found", "Datasource not found: " + dataSourceId);
}
return dataSource;
}
private void validateConnectionTestRequest(CliConnectionTestRequest request) {
boolean hasDatasourceId = request.getDataSourceId() != null;
boolean hasTemporaryField = StringUtils.isNotBlank(request.getDbType())
|| StringUtils.isNotBlank(request.getUrl())
|| StringUtils.isNotBlank(request.getHost())
|| StringUtils.isNotBlank(request.getPort())
|| StringUtils.isNotBlank(request.getDatabase())
|| StringUtils.isNotBlank(request.getUser())
|| request.getPassword() != null
|| StringUtils.isNotBlank(request.getServiceName())
|| StringUtils.isNotBlank(request.getServiceType());
if (hasDatasourceId) {
if (hasTemporaryField) {
throw new CliDomainException("invalid_connection_test_args",View on GitHub (pinned to 5ee1e990e7)
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'.
Example fix
// before
delete({ dataSourceId: 9999 }) // stale id
// after
const ds = (await list_all_datasources()).find(d => d.alias === target);
if (ds) delete({ dataSourceId: ds.id }); Defensive patterns
Strategy: try-catch
Validate before calling
WorkspaceDataSource existing = workspaceStorageFacade.queryDataSourceById(dataSourceId, false);
if (existing == null) {
// treat as already-deleted (idempotent) or refresh the list
return;
} Try / catch
try {
cliDataSourceService.delete(dataSourceId);
} catch (CliDomainException e) {
if ("datasource_not_found".equals(e.getCode())) {
return; // idempotent: already gone
}
throw e;
} Prevention
- Refresh datasource ids from list before mutating.
- Make delete handlers idempotent on not-found.
- Avoid caching datasource ids long-term across sessions.
When it happens
Trigger: DELETE datasource by an id that is absent, already deleted, or belongs to a different workspace/environment than the current context.
Common situations: Stale UI holding a deleted datasource id; the id was copied from another environment; race where the row was removed between list and delete.
Related errors
- invalid_connection_test_args
- invalid_datasource_create_args
- No database connection context found. Call list_all_datasour
- No database connection context found. Provide dataSourceId/d
- datasource_connection_failed
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/1af11e9b460235fe.
Report an issue: GitHub.