{"record":{"id":"f55a3443150e063b","repo":"apache/seatunnel","slug":"amazondocumentdb-option-must-be-a-valid-bson-js","errorCode":null,"errorMessage":"AmazonDocumentDB option '' must be a valid BSON/JSON document","messagePattern":"AmazonDocumentDB option '' must be a valid BSON/JSON document","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":200,"sourceCode":"    }\n\n    private static void validateTlsCaFile(String tlsCaFile) {\n        if (tlsCaFile == null) {\n            throw new IllegalArgumentException(\n                    \"AmazonDocumentDB option 'tls_ca_file' is required when TLS is enabled\");\n        }\n        Path path = Paths.get(tlsCaFile);\n        if (!Files.isRegularFile(path) || !Files.isReadable(path)) {\n            throw new IllegalArgumentException(\n                    \"AmazonDocumentDB TLS CA bundle is not a readable file: \" + tlsCaFile);\n        }\n    }\n\n    private static void validateBsonDocument(String value, String optionName) {\n        try {\n            BsonDocument.parse(value);\n        } catch (RuntimeException e) {\n            throw new IllegalArgumentException(\n                    \"AmazonDocumentDB option '\"\n                            + optionName\n                            + \"' must be a valid BSON/JSON document\",\n                    e);\n        }\n    }\n\n    /** Builds an isolated trust context from every X.509 certificate in the supplied CA bundle. */\n    private static SSLContext createSslContext(Path caBundlePath) {\n        try (InputStream inputStream = Files.newInputStream(caBundlePath)) {\n            CertificateFactory certificateFactory = CertificateFactory.getInstance(\"X.509\");\n            Collection<? extends Certificate> certificates =\n                    certificateFactory.generateCertificates(inputStream);\n            if (certificates.isEmpty()) {\n                throw new IllegalArgumentException(\n                        \"AmazonDocumentDB TLS CA bundle contains no certificates: \" + caBundlePath);\n            }\n","sourceCodeStart":182,"sourceCodeEnd":218,"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#L182-L218","documentation":"validateBsonDocument parses option values that must be BSON/JSON documents (e.g. match query, projection, aggregate pipeline stages) with BsonDocument.parse. If parsing throws, it wraps the cause in an IllegalArgumentException stating which option is invalid. This surfaces malformed JSON at config time instead of inside the Mongo driver.","triggerScenarios":"An option such as the match/filter query contains invalid JSON: unquoted keys, single quotes, trailing commas, or a non-document value (array/scalar).","commonSituations":"Copy-pasted filter with single quotes or unquoted keys; template placeholders (e.g. ${date}) left unexpanded producing `{\"ts\": {time}}`; a JSON array passed where a top-level document is expected.","solutions":["Validate the option value is strict JSON: quote keys with double quotes, use double-quoted strings, no trailing commas.","Test with `BsonDocument.parse(...)` or a JSON linter before deploying.","If a top-level array is needed (e.g. pipeline), put it under a document key or check whether the connector expects a document, not an array."],"exampleFix":"// before\nmatch_query = \"{'status': 'active',}\"  // single quotes + trailing comma\n// after\nmatch_query = \"{\\\"status\\\": \\\"active\\\"}\"","handlingStrategy":"validation","validationCode":"try {\n    org.bson.BsonDocument.parse(matchQuery);\n} catch (RuntimeException e) {\n    throw new IllegalArgumentException(\"match query is not valid BSON/JSON: \" + e.getMessage(), e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    BsonDocument.parse(value);\n} catch (IllegalArgumentException e) {\n    log.error(\"Invalid BSON/JSON option value\", e);\n    // surface to user, fail config load\n}","preventionTips":["Author query options in strict JSON: double-quoted keys and strings, no trailing commas.","Expand all template placeholders before validation.","Run a JSON linter on connector config query fields in CI."],"tags":["json","configuration","validation"],"backgroundTag":"invalid-json-response","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}