{"record":{"id":"f2830fd26740a21b","repo":"OtterMind/Chat2DB","slug":"database-delete-invaliddatasource","errorCode":"database.delete.invalidDataSource","errorMessage":"database.delete.invalidDataSource","messagePattern":"database\\.delete\\.invalidDataSource","errorType":"validation","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/DbDatabaseObjectDeleteServiceImpl.java","lineNumber":149,"sourceCode":"        assertConfirmName(param.getConfirmName(), schemaConfirmName(schemaName));\n        if (!StringUtils.equals(profile.getDatabaseName(), databaseName)) {\n            throw new BusinessException(\"database.delete.connectionDatabaseMismatch\");\n        }\n        Connection connection = requireConnection();\n        try {\n            assertSchemaExists(connection, databaseName, schemaName);\n            Chat2DBContext.getDbManager(dbType).dropSchema(connection, databaseName, schemaName);\n        } catch (BusinessException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new BusinessException(\"database.delete.executeFailed\", new Object[]{e.getMessage()}, e);\n        }\n    }\n\n    private ConnectionProfile requireCurrentProfile() {\n        ConnectionProfile profile = connectionContextService.currentProfile();\n        if (profile == null) {\n            throw new BusinessException(\"database.delete.invalidDataSource\");\n        }\n        return profile;\n    }\n\n    private String requireSupportedDbType(ConnectionProfile profile) {\n        String dbType = StringUtils.upperCase(StringUtils.trimToNull(profile.getDbType()));\n        if (!SUPPORTED_TYPES.contains(dbType)) {\n            throw new BusinessException(\"database.delete.notSupportDbType\");\n        }\n        return dbType;\n    }\n\n    private void reconnectForDatabaseDelete(String dbType) {\n        if (!DatabaseTypeEnum.POSTGRESQL.name().equalsIgnoreCase(dbType)) {\n            return;\n        }\n        connectionContextService.rebindCurrentDatabase(maintenanceDatabase());\n    }","sourceCodeStart":131,"sourceCodeEnd":167,"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/DbDatabaseObjectDeleteServiceImpl.java#L131-L167","documentation":"Thrown by requireCurrentProfile() when connectionContextService.currentProfile() returns null — there is no active data source profile bound to the context, so no delete operation can proceed.","triggerScenarios":"Any delete prepare/execute method is called before a connection context (and its ConnectionProfile) was established, or after the context was cleared/closed.","commonSituations":"Delete endpoint invoked without prior connect(); session/context expired; clear() ran earlier in the thread; MCP context not pushed.","solutions":["Ensure connect() succeeded and a profile is bound before calling any delete method.","Surface a 'select/refresh datasource' prompt to the user when the profile is missing rather than throwing.","Check currentProfile() for null at the controller boundary and return a 400/connect-required response."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before any delete call\nif (connectionContextService.currentProfile() == null) {\n    return Result.fail(\"database.delete.invalidDataSource\"); // or a 'connect required' response\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure connect() succeeded and a profile is bound before delete operations.","Guard delete endpoints to return 'connect required' when no profile exists.","Re-establish context after session expiry."],"tags":["database","delete","datasource","context","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}