risingwavelabs/risingwave · error · ConnectorError

NATS connect mode must be one of `user_and_password`, `crede

Error message

NATS connect mode must be one of `user_and_password`, `credential`, or `plain`

What it means

Thrown by the NATS connect-options builder when `connect_mode` holds a value outside the three supported variants: `user_and_password`, `credential`, or `plain`. The mode string is matched literally and the catch-all arm rejects anything else.

Source

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

                } 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`"
                );
            }
        };

        let servers = self.server_url.split(',').collect::<Vec<&str>>();
        let client = connect_options
            .connect(
                servers
                    .iter()
                    .map(|url| url.parse())
                    .collect::<Result<Vec<async_nats::ServerAddr>, _>>()?,
            )
            .await
            .context("failed to build the NATS client")
            .map_err(SinkError::Nats)?;
        Ok(client)
    }

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Set `connect_mode` to exactly one of: `user_and_password`, `credential`, or `plain` (lowercase).
  2. Fix spelling/casing of the connect_mode value.
  3. Omit connect_mode entirely if you want the default behavior.

Example fix

// before
WITH (connect_mode = 'user_password', user = 'u', password = 'p')
// after
WITH (connect_mode = 'user_and_password', user = 'u', password = 'p')
Defensive patterns

Strategy: validation

Validate before calling

const VALID_MODES = ['user_and_password', 'credential', 'plain'];
function validateConnectMode(mode) {
  if (mode !== undefined && !VALID_MODES.includes(mode)) {
    throw new Error(`connect_mode must be one of ${VALID_MODES.join(', ')}, got: ${mode}`);
  }
}
validateConnectMode(withOptions.connect_mode);

Type guard

const isValidMode = (m) => m === undefined || ['user_and_password', 'credential', 'plain'].includes(m);

Try / catch

try { await createNatsSink(opts); } catch (e) { if (String(e).includes('NATS connect mode must be one of')) throw new Error(`Invalid connect_mode '${opts.connect_mode}': use user_and_password, credential, or plain`); throw e; }

Prevention

When it happens

Trigger: Setting `connect_mode` to a misspelled or unsupported value like 'user_password', 'jwt', 'nkey', or 'anonymous' when creating a NATS source/sink.

Common situations: Typos, copying config from a different system with different mode names, or assuming case-insensitivity ('Plain', 'PLAIN').

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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