{"record":{"id":"bcccd092d16133ed","repo":"OtterMind/Chat2DB","slug":"database-delete-preparefailed","errorCode":"database.delete.prepareFailed","errorMessage":"database.delete.prepareFailed","messagePattern":"database\\.delete\\.prepareFailed","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/DbDatabaseObjectDeleteServiceImpl.java","lineNumber":74,"sourceCode":"    public DbDatabaseObjectDeleteServiceImpl(IDbConnectionContextService connectionContextService) {\n        this.connectionContextService = connectionContextService;\n    }\n\n    @Override\n    public DatabaseObjectDeletePrepare prepareDatabaseDelete(DbDatabaseDeletePrepareRequest param) {\n        ConnectionProfile profile = requireCurrentProfile();\n        String dbType = requireSupportedDbType(profile);\n        reconnectForDatabaseDelete(dbType);\n        String databaseName = requireName(param.getDatabaseName(), \"databaseName\");\n        assertDatabaseDeletionSupported(dbType);\n        rejectSystemDatabase(dbType, databaseName);\n        Connection connection = requireConnection();\n        try {\n            assertDatabaseExists(connection, dbType, databaseName);\n        } catch (BusinessException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new BusinessException(\"database.delete.prepareFailed\", new Object[]{e.getMessage()}, e);\n        }\n        return prepareResult(databaseConfirmName(databaseName), buildDropDatabase(dbType, databaseName),\n                TYPE_DATABASE, dbType);\n    }\n\n    @Override\n    public DatabaseObjectDeletePrepare prepareSchemaDelete(DbSchemaDeletePrepareRequest param) {\n        ConnectionProfile profile = requireCurrentProfile();\n        String dbType = requireSupportedDbType(profile);\n        String databaseName = requireName(param.getDatabaseName(), \"databaseName\");\n        String schemaName = requireName(param.getSchemaName(), \"schemaName\");\n        assertSchemaDeletionSupported(dbType);\n        rejectSystemSchema(dbType, schemaName);\n        Connection connection = requireConnection();\n        try {\n            assertSchemaExists(connection, databaseName, schemaName);\n        } catch (BusinessException e) {\n            throw e;","sourceCodeStart":56,"sourceCodeEnd":92,"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#L56-L92","documentation":"Wraps any non-BusinessException raised during prepareDatabaseDelete() while asserting the target database exists (assertDatabaseExists). The prepare step validates the database is present before producing the drop SQL; an unexpected failure here is reported as 'Failed to prepare deletion: {0}'.","triggerScenarios":"prepareDatabaseDelete() reaches assertDatabaseExists(connection, dbType, databaseName) and the metadata lookup throws a SQLException or other non-Business error (e.g. connection lost, driver metadata failure).","commonSituations":"Connection dropped between reconnectForDatabaseDelete and the existence check, the dialect's metadata query is unsupported, or permissions prevent listing databases.","solutions":["Read the wrapped cause ({0} = e.getMessage()) to find the underlying JDBC error.","Ensure the maintenance connection is alive (reconnectForDatabaseDelete succeeded) and the user has metadata privileges.","Re-run the prepare step after reconnecting."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    deleteService.prepareDatabaseDelete(param);\n} catch (BusinessException e) {\n    if (\"database.delete.prepareFailed\".equals(e.getCode())) {\n        // inspect e.getCause() (SQLException) and e.getArgs()[0] for the reason\n    } else {\n        throw e;\n    }\n}","preventionTips":["Ensure the maintenance connection is alive before prepare.","Grant metadata/list privileges to the role.","Reconnect and retry prepare on transient failures."],"tags":["database","delete","ddl","prepare","jdbc"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}