{"record":{"id":"cbe83645cb7d891c","repo":"apache/seatunnel","slug":"invalid-amazondocumentdb-connection-uri-in-option","errorCode":null,"errorMessage":"Invalid AmazonDocumentDB connection URI in option 'uri'","messagePattern":"Invalid AmazonDocumentDB connection URI in option 'uri'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/config/AmazonDocumentDBConfig.java","lineNumber":139,"sourceCode":"        MongoClientSettings.Builder builder =\n                MongoClientSettings.builder()\n                        .applyConnectionString(connectionString)\n                        .retryWrites(false);\n        builder.applyToSslSettings(\n                sslBuilder -> {\n                    sslBuilder.enabled(tls);\n                    if (tls) {\n                        sslBuilder.context(createSslContext(Paths.get(tlsCaFile)));\n                    }\n                });\n        return builder.build();\n    }\n\n    private static ConnectionString parseConnectionString(String uri) {\n        try {\n            return new ConnectionString(uri);\n        } catch (IllegalArgumentException e) {\n            throw new IllegalArgumentException(\n                    \"Invalid AmazonDocumentDB connection URI in option 'uri'\", e);\n        }\n    }\n\n    private static boolean hasRetryWritesEnabled(String uri) {\n        int queryStart = uri.indexOf('?');\n        if (queryStart < 0 || queryStart == uri.length() - 1) {\n            return false;\n        }\n        String query = uri.substring(queryStart + 1);\n        int fragmentStart = query.indexOf('#');\n        if (fragmentStart >= 0) {\n            query = query.substring(0, fragmentStart);\n        }\n        for (String parameter : query.split(\"&\")) {\n            int separator = parameter.indexOf('=');\n            if (separator < 0) {\n                continue;","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/config/AmazonDocumentDBConfig.java#L121-L157","documentation":"parseConnectionString wraps the MongoDB driver's ConnectionString parser: when the 'uri' option is not a valid MongoDB connection string, the driver's IllegalArgumentException is rethrown as \"Invalid AmazonDocumentDB connection URI in option 'uri'\" with the original cause preserved, attributing the failure to the 'uri' option.","triggerScenarios":"Job startup where option 'uri' fails new ConnectionString(uri): missing mongodb:// scheme, malformed host list, unparseable options after '?', or illegal characters in username/password (e.g. a raw '@' or ':' in an unencoded password).","commonSituations":"Special characters in passwords not URL-encoded (very common: @, #, %); missing 'mongodb://' prefix when pasting a raw cluster endpoint; stray quotes or whitespace from env-var templating; copy-paste of an aws docdb endpoint alone, which is not a URI.","solutions":["Ensure the uri starts with mongodb:// — a bare DocumentDB endpoint is not a valid connection string","URL-encode username and password: escape @ : / ? # % (e.g. p@ss -> p%40ss)","Strip surrounding quotes/whitespace if the value came from an env variable or templating engine","Test the uri with mongosh or the MongoDB ConnectionString parser to see the driver's underlying cause"],"exampleFix":"// before\nuri = \"docdb-cluster.cluster-xxxx.us-east-1.docdb.amazonaws.com:27017\"  // no scheme\n// after\nuri = \"mongodb://admin:p%40ss@docdb-cluster.cluster-xxxx.us-east-1.docdb.amazonaws.com:27017/?tls=true&tlsCAFile=rds-ca.crt\"","handlingStrategy":"validation","validationCode":"// validate the uri shape before submitting the job\nfunction assertValidMongoUri(uri) {\n  if (!/^mongodb(\\+srv)?:\\/\\//.test(uri)) {\n    throw new Error(\"uri must start with mongodb:// or mongodb+srv://\");\n  }\n  if (uri !== uri.trim()) {\n    throw new Error(\"uri has surrounding whitespace\");\n  }\n}\nassertValidMongoUri(process.env.DOCDB_URI);","typeGuard":"boolean looksLikeMongoUri(String uri) {\n  return uri != null && uri.trim().startsWith(\"mongodb://\");\n}","tryCatchPattern":"try {\n    AmazonDocumentDBConfig config = new AmazonDocumentDBConfig(readonlyConfig);\n} catch (IllegalArgumentException e) {\n    if (String.valueOf(e.getMessage()).contains(\"Invalid AmazonDocumentDB connection URI\")) {\n        // e.getCause() is the driver's original parse error — surface it for the exact offending token\n        throw new IllegalArgumentException(\"Bad 'uri' option: \"\n            + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), e);\n    }\n    throw e;\n}","preventionTips":["URL-encode username and password (@ -> %40, : -> %3A, etc.) before embedding in the uri","Always include the mongodb:// scheme; a bare DocumentDB endpoint is not a URI","Trim whitespace and stray quotes from values injected via env variables or templating","Sanity-check the uri with mongosh or the driver's ConnectionString class in a unit test before deploy"],"tags":["amazondocumentdb","mongodb-uri","url-parsing","config-error"],"backgroundTag":"invalid-url-format","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}