nautechsystems/nautilus_trader · error · anyhow::Error

VNC port must be between 5900 and 5999

Error message

VNC port must be between 5900 and 5999

What it means

Config validation in the InteractiveBrokers client configuration: the optional vnc_port falls outside the standard VNC port range 5900-5999, so the config is rejected as it cannot reference a real VNC listener.

Source

Thrown at crates/adapters/interactive_brokers/src/config.rs:370

    /// Validate configuration.
    ///
    /// # Errors
    ///
    /// Returns an error if validation fails.
    pub fn validate(&self) -> anyhow::Result<()> {
        if self.timeout == 0 {
            anyhow::bail!("Timeout must be greater than 0");
        }

        if self.timeout > 3600 {
            anyhow::bail!("Timeout must be less than 3600 seconds");
        }

        if let Some(port) = self.vnc_port
            && (!(5900..=5999).contains(&port))
        {
            anyhow::bail!("VNC port must be between 5900 and 5999");
        }

        Ok(())
    }
}

impl Default for DockerizedIBGatewayConfig {
    fn default() -> Self {
        Self::builder()
            .maybe_username(std::env::var("TWS_USERNAME").ok().map(SecretString::from))
            .maybe_password(std::env::var("TWS_PASSWORD").ok().map(SecretString::from))
            .build()
    }
}

#[cfg(test)]
mod tests {
    use rstest::rstest;

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Set vnc_port to a value in 5900..=5999 (e.g. 5900)
  2. If you have a display number N, use port 5900 + N
  3. Leave vnc_port as None if VNC is not needed

Example fix

// before
let config = IbAccountConfig { vnc_port: Some(4001), ..base }; // gateway port
// after
let config = IbAccountConfig { vnc_port: Some(5900), ..base };
Defensive patterns

Strategy: validation

Validate before calling

if let Some(p) = config.vnc_port { assert!((5900..=5999).contains(&p), "VNC port must be 5900..=5999"); }

Try / catch

if let Err(e) = config.validate() {
    if e.to_string().contains("VNC port") {
        eprintln!("{} is not a VNC port; use 5900 + display number", config.vnc_port.unwrap_or(0));
    }
    anyhow::bail!(e);
}

Prevention

When it happens

Trigger: Calling validate() with Some(port) where port < 5900 or > 5999 — e.g. supplying the display number (0, 1, :0) instead of the port, or an HTTP gateway port (4001/4002).

Common situations: Confusing the VNC display number with the port; copying the gateway port into vnc_port; typos like 59000 vs 5900.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/49a6dde2cccf81d2. Report an issue: GitHub.