risingwavelabs/risingwave · error · ConnectorError

NATS connect mode `user_and_password` requires both `user` a

Error message

NATS connect mode `user_and_password` requires both `user` and `password`

What it means

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.

Source

Thrown at src/connector/src/connector_common/common.rs:1055

            user: self.user.clone(),
            password: self.password.clone(),
            jwt: self.jwt.clone(),
            nkey: self.nkey.clone(),
        }
    }

    /// Build a new NATS client without caching.
    async fn build_client_inner(&self) -> ConnectorResult<async_nats::Client> {
        let mut connect_options = async_nats::ConnectOptions::new();
        match self.connect_mode.as_str() {
            "user_and_password" => {
                if let (Some(v_user), Some(v_password)) =
                    (self.user.as_ref(), self.password.as_ref())
                {
                    connect_options =
                        connect_options.user_and_password(v_user.into(), v_password.into())
                } else {
                    bail!(
                        "NATS connect mode `user_and_password` requires both `user` and `password`"
                    );
                }
            }

            "credential" => {
                if let (Some(v_nkey), Some(v_jwt)) = (self.nkey.as_ref(), self.jwt.as_ref()) {
                    connect_options = connect_options
                        .credentials(&self.create_credential(v_nkey, v_jwt)?)
                        .expect("failed to parse static creds")
                } else {
                    bail!("NATS connect mode `credential` requires both `nkey` and `jwt`");
                }
            }
            "plain" => {}
            _ => {
                bail!(
                    "NATS connect mode must be one of `user_and_password`, `credential`, or `plain`"

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Set both `user` and `password` fields in the connector properties.
  2. Verify the referenced secrets resolve to non-empty values at runtime.
  3. If anonymous access is intended, set `connect_mode = 'plain'` instead.

Example fix

// before
WITH (connect_mode = 'user_and_password', user = 'nats_user') -- password missing
// after
WITH (connect_mode = 'user_and_password', user = 'nats_user', password = 'secret')
Defensive patterns

Strategy: validation

Validate before calling

function validateNatsAuth(props) {
  if (props.connect_mode === 'user_and_password') {
    if (!props.user || !props.password) throw new Error('user_and_password mode requires both user and password');
  }
}
validateNatsAuth(withOptions);

Type guard

const hasUserPassword = (p) => typeof p.user === 'string' && p.user.length > 0 && typeof p.password === 'string' && p.password.length > 0;

Try / catch

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; }

Prevention

When it happens

Trigger: Creating a NATS source/sink with `connect_mode = 'user_and_password'` while leaving `user` or `password` (or both) unset in the WITH/properties.

Common situations: 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.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/43c04cc7e7a70179. Report an issue: GitHub.