{"record":{"id":"ec1d32163dc8a6e5","repo":"OtterMind/Chat2DB","slug":"invalid-datasource-create-args","errorCode":"invalid_datasource_create_args","errorMessage":"datasource-create requires dbType","messagePattern":"datasource-create requires dbType","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":201,"sourceCode":"        }\n    }\n\n    private void normalizeConnectionTestRequest(CliConnectionTestRequest request) {\n        request.setDbType(canonicalDbType(request.getDbType()));\n    }\n\n    private DbDataSourcePreConnectRequest buildPreConnectParam(CliConnectionTestRequest source) {\n        if (source.getDataSourceId() != null) {\n            return existingDatasourcePreConnectParam(source.getDataSourceId());\n        }\n        String url = JdbcUrlUtils.resetUrl(connectionTestUrl(source), source.getDbType(), source.getServiceType());\n        return cliDataSourceConverter.connectionTest2param(source, url, defaultSsh(source.getSsh()),\n                defaultDriverConfig(source.getDriverConfig(), source.getDbType()));\n    }\n\n    private void validateCreateRequest(CliDataSourceCreateRequest request) {\n        if (StringUtils.isBlank(request.getDbType())) {\n            throw new CliDomainException(\"invalid_datasource_create_args\", \"datasource-create requires dbType\");\n        }\n        if (request.getEnvironmentId() == null) {\n            throw new CliDomainException(\"invalid_datasource_create_args\", \"datasource-create requires environmentId\");\n        }\n        if (request.getPassword() == null) {\n            throw new CliDomainException(\"invalid_datasource_create_args\", \"datasource-create requires 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_datasource_create_args\",\n                    \"url cannot be combined with host, port, or database\");\n        }\n        if (!hasUrl && !(StringUtils.isNotBlank(request.getHost())\n                && StringUtils.isNotBlank(request.getPort())\n                && StringUtils.isNotBlank(request.getDatabase()))) {","sourceCodeStart":183,"sourceCodeEnd":219,"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#L183-L219","documentation":"CliDomainException code invalid_datasource_create_args from validateCreateRequest: dbType must be non-blank to create a datasource. dbType is required first because subsequent normalization and driver defaults depend on it.","triggerScenarios":"POST datasource create without a dbType field (or blank), while other fields may be present.","commonSituations":"UI/automation that leaves dbType unset or sends an empty string; a malformed payload that dropped the type.","solutions":["Set dbType to a supported value (e.g. MYSQL, POSTGRESQL, ORACLE) in the create request.","Validate the request payload shape before sending; dbType is mandatory."],"exampleFix":"// before\ncreate({ host, port, database, user, password, environmentId })\n\n// after\ncreate({ dbType: 'POSTGRESQL', host, port, database, user, password, environmentId })","handlingStrategy":"validation","validationCode":"if (StringUtils.isBlank(request.getDbType())) {\n    throw new IllegalArgumentException(\"dbType is required to create a datasource\");\n}","typeGuard":"public boolean hasDbType(CliDataSourceCreateRequest r) {\n    return r != null && StringUtils.isNotBlank(r.getDbType());\n}","tryCatchPattern":"try {\n    cliDataSourceService.create(request);\n} catch (CliDomainException e) {\n    if (\"invalid_datasource_create_args\".equals(e.getCode())) {\n        return badRequest(e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Make dbType a required field in the request DTO/UI form.","Validate the create payload schema before sending."],"tags":["datasource","validation","cli","create"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}