zed-industries/zed · error

Invalid port forward format: {spec}

Error message

Invalid port forward format: {spec}

What it means

Parsing guard for ssh -L/-R forward specs: the spec tokenized to a count outside the supported 1/2/3-token shapes (e.g. too many colons or empty segments), so SshPortForwardOption cannot be constructed.

Source

Thrown at crates/remote/src/transport/ssh.rs:1648

            Ok(SshPortForwardOption {
                local_host: Some(tokens[0].clone()),
                local_port,
                remote_host: Some(tokens[2].clone()),
                remote_port,
            })
        }
        3 => {
            let local_port = parse_port_number(&tokens[0])?;
            let remote_port = parse_port_number(&tokens[2])?;

            Ok(SshPortForwardOption {
                local_host: None,
                local_port,
                remote_host: Some(tokens[1].clone()),
                remote_port,
            })
        }
        _ => anyhow::bail!("Invalid port forward format: {spec}"),
    }
}

impl SshConnectionOptions {
    pub fn parse_command_line(input: &str) -> Result<Self> {
        let input = input.trim_start_matches("ssh ");
        let mut hostname: Option<String> = None;
        let mut username: Option<String> = None;
        let mut port: Option<u16> = None;
        let mut args = Vec::new();
        let mut port_forwards: Vec<SshPortForwardOption> = Vec::new();

        // disallowed: -E, -e, -F, -f, -G, -g, -M, -N, -n, -O, -q, -S, -s, -T, -t, -V, -v, -W
        const ALLOWED_OPTS: &[&str] = &[
            "-4", "-6", "-A", "-a", "-C", "-K", "-k", "-X", "-x", "-Y", "-y",
        ];
        const ALLOWED_ARGS: &[&str] = &[
            "-B", "-b", "-c", "-D", "-F", "-I", "-i", "-J", "-l", "-m", "-o", "-P", "-p", "-R",

View on GitHub (pinned to f4178619ac)

Solutions

  1. Use a standard form: `port`, `host:port`, `local:port:remote:port`, or `host:port:remote:port`
  2. Check for stray colons or empty segments in the forward specification
  3. Remove malformed -L/-R arguments from the SSH options
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/remote/src/transport/ssh.rs:1648 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/8729f963c9dfbebf. Report an issue: GitHub.