{"record":{"id":"42019830ac5dfd86","repo":"OtterMind/Chat2DB","slug":"connection-error-420198","errorCode":"connection error","errorMessage":"connection error","messagePattern":"connection error","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/DbConnectionContextServiceImpl.java","lineNumber":82,"sourceCode":"            Chat2DBContext.putContext(connectInfo);\n        }\n    }\n\n    @Override\n    public void bindMcp(McpConnectionContextRequest param) {\n        Chat2DBContext.putContext(buildMcpConnectInfo(param));\n    }\n\n    @Override\n    public void clear() {\n        Chat2DBContext.removeContext();\n    }\n\n    @Override\n    public void rebindCurrentDatabase(String databaseName) {\n        ConnectInfo connectInfo = Chat2DBContext.getConnectInfo();\n        if (connectInfo == null) {\n            throw new BusinessException(\"connection error\");\n        }\n        Chat2DBContext.removeContext();\n        connectInfo.setDatabaseName(databaseName);\n        connectInfo.setConnection(null);\n        Chat2DBContext.putContext(connectInfo);\n    }\n\n    @Override\n    public void close() {\n        Chat2DBContext.close();\n    }\n\n    @Override\n    public ConnectionProfile currentProfile() {\n        ConnectInfo connectInfo = Chat2DBContext.getConnectInfo();\n        if (connectInfo == null) {\n            return null;\n        }","sourceCodeStart":64,"sourceCodeEnd":100,"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/DbConnectionContextServiceImpl.java#L64-L100","documentation":"Thrown by rebindCurrentDatabase() when Chat2DBContext.getConnectInfo() is null — there is no active ConnectInfo on the thread to rebind to a new database. The space-separated key 'connection error' will not resolve against the dotted i18n property 'connection.error'.","triggerScenarios":"A database switch request (switching the active database on the current connection) arrives when no connection context exists — e.g. switch-database called before connect(), or after clear()/close() ran.","commonSituations":"Frontend sends a 'switch database' action for a datasource that was never connected, or after the session/context expired; MCP rebind invoked out of order.","solutions":["Ensure connect() succeeded and pushed a ConnectInfo before calling rebindCurrentDatabase().","If the context can legitimately be absent, treat it as 'must connect first' and surface a connect prompt rather than throwing.","Fix the key to 'connection.error' so the i18n message resolves correctly."],"exampleFix":"// before\nthrow new BusinessException(\"connection error\");\n// after\nthrow new BusinessException(\"connection.error\");","handlingStrategy":"validation","validationCode":"// Before switching database\nif (Chat2DBContext.getConnectInfo() == null) {\n    // no active connection: require connect() first\n    return Result.fail(\"connection.error\");\n}\ndbConnectionContextService.rebindCurrentDatabase(databaseName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure connect() ran and pushed a ConnectInfo before any switch-database call.","Guard the switch endpoint so a missing context returns 'connect required' instead of throwing.","Use the dotted 'connection.error' key so the message resolves."],"tags":["connection","context","database-switch","i18n"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}