{"record":{"id":"6ffeeb3986b9610d","repo":"OtterMind/Chat2DB","slug":"connection-error-6ffeeb","errorCode":"connection error","errorMessage":"connection error","messagePattern":"connection error","errorType":"validation","errorClass":"BusinessException","httpStatus":null,"severity":"critical","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbDlTemplateServiceImpl.java","lineNumber":76,"sourceCode":"        if (StringUtils.isBlank(param.getSql())) {\n            return Collections.emptyList();\n        }\n        long s1 = System.currentTimeMillis();\n        ICommandExecutor executor = Chat2DBContext.getDbMetaData().getCommandExecutor();\n        SqlExecuteRequest command = commandConverter.param2model(param);\n        List<ExecuteResponse> results = executor.execute(command);\n        long s2 = System.currentTimeMillis();\n        log.info(\"execute_sql cost time:{}\", s2 - s1);\n        List<ExecuteResponse> r = reBuildHeader(results, param.getDataSourceId(), param.getSchemaName(),\n                param.getDatabaseName());\n        log.info(\"execute_header cost time:{}\", System.currentTimeMillis() - s2);\n        return r;\n    }\n\n    @Override\n    public ExecuteResponse executeDdl(DbDlExecuteRequest param) {\n        if (Chat2DBContext.getConnection() == null) {\n            throw new BusinessException(\"connection error\");\n        }\n        List<ExecuteResponse> result = execute(param);\n        if (CollectionUtils.isEmpty(result)) {\n            return null;\n        }\n        for (ExecuteResponse executeResult : result) {\n            if (!Boolean.TRUE.equals(executeResult.getSuccess())) {\n                return executeResult;\n            }\n        }\n        ExecuteResponse executeResult = result.get(0);\n        if (StringUtils.isBlank(param.getTableName())) {\n            executeResult.setTableName(SqlUtils.extractTableName(executeResult.getOriginalSql()));\n        }\n        return executeResult;\n    }\n\n    @Override","sourceCodeStart":58,"sourceCodeEnd":94,"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/DbDlTemplateServiceImpl.java#L58-L94","documentation":"Thrown by executeDdl when Chat2DBContext.getConnection() returns null at the start of the method — a pre-flight check before delegating to execute(). Unlike the update-path 'connection error' variants, this one carries no cause or message args; it is a pure guard that the thread has a bound JDBC connection before attempting DDL. Indicates the connection context was never established for this request.","triggerScenarios":"Calling executeDdl(param) when no connection is bound in Chat2DBContext — e.g., the connection-scoping interceptor did not run, the pool failed to provide a connection, or a prior operation closed it.","commonSituations":"Service invoked outside the normal web-request connection scope; connection pool exhausted or DB unreachable so binding silently failed; unit test calling executeDdl without setting up Chat2DBContext.","solutions":["Ensure executeDdl is called within the request lifecycle that binds a connection via connectionContextService.","Verify datasource connectivity and pool health.","In tests, bind a mock connection to Chat2DBContext before calling."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (Chat2DBContext.getConnection() == null) {\n    // surface connection-setup error; do not call executeDdl\n}","typeGuard":null,"tryCatchPattern":"try {\n    service.executeDdl(req);\n} catch (BusinessException e) {\n    if (\"connection error\".equals(e.getCode()) && e.getCause() == null) {\n        // this is the ddl pre-flight null-connection guard\n    } else { throw e; }\n}","preventionTips":["Ensure the connection-binding request scope wraps every executeDdl call.","In tests, always bind a connection to Chat2DBContext before invocation."],"tags":["ddl","connection","context-missing"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}