{"record":{"id":"43c04cc7e7a70179","repo":"risingwavelabs/risingwave","slug":"nats-connect-mode-user-and-password-requires-bot","errorCode":null,"errorMessage":"NATS connect mode `user_and_password` requires both `user` and `password`","messagePattern":"NATS connect mode `user_and_password` requires both `user` and `password`","errorType":"validation","errorClass":"ConnectorError","httpStatus":null,"severity":"error","filePath":"src/connector/src/connector_common/common.rs","lineNumber":1055,"sourceCode":"            user: self.user.clone(),\n            password: self.password.clone(),\n            jwt: self.jwt.clone(),\n            nkey: self.nkey.clone(),\n        }\n    }\n\n    /// Build a new NATS client without caching.\n    async fn build_client_inner(&self) -> ConnectorResult<async_nats::Client> {\n        let mut connect_options = async_nats::ConnectOptions::new();\n        match self.connect_mode.as_str() {\n            \"user_and_password\" => {\n                if let (Some(v_user), Some(v_password)) =\n                    (self.user.as_ref(), self.password.as_ref())\n                {\n                    connect_options =\n                        connect_options.user_and_password(v_user.into(), v_password.into())\n                } else {\n                    bail!(\n                        \"NATS connect mode `user_and_password` requires both `user` and `password`\"\n                    );\n                }\n            }\n\n            \"credential\" => {\n                if let (Some(v_nkey), Some(v_jwt)) = (self.nkey.as_ref(), self.jwt.as_ref()) {\n                    connect_options = connect_options\n                        .credentials(&self.create_credential(v_nkey, v_jwt)?)\n                        .expect(\"failed to parse static creds\")\n                } else {\n                    bail!(\"NATS connect mode `credential` requires both `nkey` and `jwt`\");\n                }\n            }\n            \"plain\" => {}\n            _ => {\n                bail!(\n                    \"NATS connect mode must be one of `user_and_password`, `credential`, or `plain`\"","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/connector_common/common.rs#L1037-L1073","documentation":"Thrown while building NATS connect options in connector_common/common.rs when the connector's connect mode is `user_and_password` but either `user` or `password` is missing. async-nats requires both values to construct the auth pair.","triggerScenarios":"Creating a NATS source/sink with `connect_mode = 'user_and_password'` while leaving `user` or `password` (or both) unset in the WITH/properties.","commonSituations":"Secrets not injected (password field empty in the secret store), copy-pasted config omitting one field, or switching connect mode without updating all required fields.","solutions":["Set both `user` and `password` fields in the connector properties.","Verify the referenced secrets resolve to non-empty values at runtime.","If anonymous access is intended, set `connect_mode = 'plain'` instead."],"exampleFix":"// before\nWITH (connect_mode = 'user_and_password', user = 'nats_user') -- password missing\n// after\nWITH (connect_mode = 'user_and_password', user = 'nats_user', password = 'secret')","handlingStrategy":"validation","validationCode":"function validateNatsAuth(props) {\n  if (props.connect_mode === 'user_and_password') {\n    if (!props.user || !props.password) throw new Error('user_and_password mode requires both user and password');\n  }\n}\nvalidateNatsAuth(withOptions);","typeGuard":"const hasUserPassword = (p) => typeof p.user === 'string' && p.user.length > 0 && typeof p.password === 'string' && p.password.length > 0;","tryCatchPattern":"try { await createNatsSink(opts); } catch (e) { if (String(e).includes('requires both `user` and `password`')) throw new Error('Set both user and password in WITH options, or use connect_mode = plain'); throw e; }","preventionTips":["Group user+password in one secret so both resolve together.","Validate the full option set against connect_mode before submitting DDL.","Use connect_mode = 'plain' when the NATS server allows anonymous access."],"tags":["nats","authentication","config","validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}