{"record":{"id":"6b6acf96104f07c8","repo":"OtterMind/Chat2DB","slug":"invalid-connection-test-args","errorCode":"invalid_connection_test_args","errorMessage":"--data-source-id cannot be combined with temporary connection parameters","messagePattern":"--data-source-id cannot be combined with temporary connection parameters","errorType":"validation","errorClass":"CliDomainException","httpStatus":null,"severity":"warning","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/cli/CliDataSourceServiceImpl.java","lineNumber":159,"sourceCode":"            throw new CliDomainException(\"datasource_not_found\", \"Datasource not found: \" + dataSourceId);\n        }\n        return dataSource;\n    }\n\n    private void validateConnectionTestRequest(CliConnectionTestRequest request) {\n        boolean hasDatasourceId = request.getDataSourceId() != null;\n        boolean hasTemporaryField = StringUtils.isNotBlank(request.getDbType())\n                || StringUtils.isNotBlank(request.getUrl())\n                || StringUtils.isNotBlank(request.getHost())\n                || StringUtils.isNotBlank(request.getPort())\n                || StringUtils.isNotBlank(request.getDatabase())\n                || StringUtils.isNotBlank(request.getUser())\n                || request.getPassword() != null\n                || StringUtils.isNotBlank(request.getServiceName())\n                || StringUtils.isNotBlank(request.getServiceType());\n        if (hasDatasourceId) {\n            if (hasTemporaryField) {\n                throw new CliDomainException(\"invalid_connection_test_args\",\n                        \"--data-source-id cannot be combined with temporary connection parameters\");\n            }\n            return;\n        }\n        if (StringUtils.isBlank(request.getDbType())\n                || StringUtils.isBlank(request.getUser())\n                || StringUtils.isBlank(request.getPassword())) {\n            throw new CliDomainException(\"invalid_connection_test_args\",\n                    \"temporary mode requires dbType, user, and password\");\n        }\n        boolean hasUrl = StringUtils.isNotBlank(request.getUrl());\n        boolean hasHostFields = StringUtils.isNotBlank(request.getHost())\n                || StringUtils.isNotBlank(request.getPort())\n                || StringUtils.isNotBlank(request.getDatabase());\n        if (hasUrl && hasHostFields) {\n            throw new CliDomainException(\"invalid_connection_test_args\",\n                    \"url cannot be combined with host, port, or database\");\n        }","sourceCodeStart":141,"sourceCodeEnd":177,"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/cli/CliDataSourceServiceImpl.java#L141-L177","documentation":"CliDomainException code invalid_connection_test_args from validateConnectionTestRequest: when request.dataSourceId is present AND any temporary connection field (dbType, url, host, port, database, user, password, serviceName, serviceType) is also non-blank. The connection test is intentionally one-mode-only.","triggerScenarios":"Calling connection-test with both a dataSourceId and host/url/user/etc., expecting the temp fields to override the stored datasource.","commonSituations":"CLI flag mix-up: passing --data-source-id together with --host/--url; an automation script defaulting fields while also referencing a saved datasource.","solutions":["To test a saved datasource: pass ONLY dataSourceId.","To test a temporary connection: omit dataSourceId and provide dbType plus connection fields.","Audit the CLI/script invocation for accidentally-set default values on temporary fields."],"exampleFix":"# before\ntest --data-source-id 5 --host db.prod --port 3306\n\n# after (test saved datasource only)\ntest --data-source-id 5","handlingStrategy":"validation","validationCode":"boolean hasId = request.getDataSourceId() != null;\nboolean hasTemp = Stream.of(request.getDbType(), request.getUrl(), request.getHost(),\n        request.getPort(), request.getDatabase(), request.getUser(), request.getServiceName(), request.getServiceType())\n        .anyMatch(StringUtils::isNotBlank) || request.getPassword() != null;\nif (hasId && hasTemp) {\n    throw new IllegalArgumentException(\"Choose either dataSourceId or temporary fields, not both\");\n}","typeGuard":"public boolean isTemporaryMode(CliConnectionTestRequest r) {\n    return r != null && r.getDataSourceId() == null;\n}","tryCatchPattern":"try {\n    cliDataSourceService.testConnection(request);\n} catch (CliDomainException e) {\n    if (\"invalid_connection_test_args\".equals(e.getCode())) {\n        return badRequest(e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Validate mutual exclusivity of dataSourceId vs. temp fields at the CLI/parser boundary.","Avoid defaulting temp fields when referencing a saved datasource.","Document one-mode-per-call clearly in CLI help text."],"tags":["datasource","validation","cli","connection-test"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}