herdrdev/herdr · warning · io::Error

{flag} must be an integer between 1 and {}

Error message

{flag} must be an integer between 1 and {}

What it means

parse_terminal_dimension rejects CLI strings that cannot be parsed as a u16 (src/cli.rs:665). It is used for terminal size flags such as rows/columns on commands that open a terminal session. The error is io::ErrorKind::InvalidInput with a message naming the offending flag and the valid range 1..=65535.

Source

Thrown at src/cli.rs:665

            other => {
                eprintln!("unknown terminal session {command} option: {other}");
                eprintln!("{usage}");
                return Ok(Err(2));
            }
        }
    }

    Ok(Ok(TerminalSessionOptions {
        target: target.clone(),
        cols,
        rows,
        takeover,
    }))
}

fn parse_terminal_dimension(raw: &str, flag: &str) -> std::io::Result<u16> {
    let parsed = raw.parse::<u16>().map_err(|_| {
        std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            format!("{flag} must be an integer between 1 and {}", u16::MAX),
        )
    })?;
    if parsed == 0 {
        return Err(std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            format!("{flag} must be greater than 0"),
        ));
    }
    Ok(parsed)
}

fn terminal_title(args: &[String]) -> std::io::Result<i32> {
    match args.first().map(|arg| arg.as_str()) {
        Some("set") => {
            if args.len() != 2 {
                eprintln!("usage: herdr terminal title set <title>");

View on GitHub (pinned to f457cff4f2)

Solutions

  1. Pass a plain integer between 1 and 65535, e.g. --rows 24 --cols 80
  2. Quote and trim shell variables: --rows "${ROWS:-24}"
  3. Validate dimension input in wrapper scripts before invoking herdr

Example fix

# before
herdr session new --rows abc --cols 80

# after
herdr session new --rows 24 --cols 80
Defensive patterns

Strategy: validation

Validate before calling

fn valid_dimension(s: &str) -> bool {
    s.chars().all(|c| c.is_ascii_digit())
        && s.parse::<u16>().map(|v| v >= 1).unwrap_or(false)
}

Prevention

When it happens

Trigger: Passing --rows/--cols (or whichever terminal dimension flag) a non-numeric string, a negative number, a decimal like "80.5", or a value above 65535 to a CLI command parsed by parse_terminal_session_options.

Common situations: Typos in flags, passing an empty string from a shell variable, using expressions like $COLUMNS with stray whitespace, or scripts piping unset variables ("").

Related errors


AI-assisted analysis of herdrdev/herdr@f457cff4f2 (2026-08-28). Data as JSON: /api/errors/570093da03e4467d. Report an issue: GitHub.