xai-org/grok-build · error · anyhow::Error

invalid size format, expected COLSxROWS (e.g. 120x40)

Error message

invalid size format, expected COLSxROWS (e.g. 120x40)

What it means

ptyctl's resize command expects the size argument in the strict COLSxROWS form (e.g. 120x40), parsed by splitting on 'x'. This error is thrown when the string contains no 'x' separator, so it cannot be split into columns and rows.

Source

Thrown at crates/codegen/ptyctl-cli/src/commands/client.rs:131

/// Query session status.
pub async fn status(url: &str) -> Result<()> {
    let client = client_for(url)?;
    let resp = client
        .get(format!("{url}/query/status"))
        .send()
        .await
        .context("failed to query status")?;
    let body = resp.text().await?;
    println!("{body}");
    Ok(())
}

/// Resize terminal.
pub async fn resize(url: &str, size: &str) -> Result<()> {
    let (cols, rows) = size
        .split_once('x')
        .ok_or_else(|| anyhow::anyhow!("invalid size format, expected COLSxROWS (e.g. 120x40)"))?;
    let cols: u16 = cols.parse().context("invalid cols")?;
    let rows: u16 = rows.parse().context("invalid rows")?;

    let client = client_for(url)?;
    let resp = client
        .post(format!("{url}/control/resize"))
        .json(&serde_json::json!({"cols": cols, "rows": rows}))
        .send()
        .await
        .context("failed to resize")?;

    if !resp.status().is_success() {
        let body = resp.text().await.unwrap_or_default();
        anyhow::bail!("resize failed: {body}");
    }
    println!("Resized to {cols}x{rows}");
    Ok(())
}

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Pass the size as COLSxROWS with a lowercase x, e.g. 120x40
  2. Replace other separators in your script: convert "120,40" or "120 40" to "120x40"
  3. Check that no shell quoting/variable expansion is mangling the argument before it reaches ptyctl

Example fix

// before
ptyctl resize http://127.0.0.1:9999 120,40
// after
ptyctl resize http://127.0.0.1:9999 120x40
Defensive patterns

Strategy: validation

Validate before calling

fn parse_size(size: &str) -> anyhow::Result<(u16, u16)> {
    let (c, r) = size.split_once('x').ok_or_else(|| anyhow::anyhow!("invalid size format, expected COLSxROWS (e.g. 120x40)"))?;
    Ok((c.parse()?, r.parse()?))
}

Try / catch

match ptyctl::commands::client::resize(&url, &size).await {
    Err(e) if e.to_string().contains("invalid size format") => {
        eprintln!("use COLSxROWS, e.g. 120x40 (got: {size})");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running `ptyctl resize <url> <size>` (the resize function in commands/client.rs) with a size like "120,40", "120 40", "120*40", "120X40" (capital X), or just "120" — any string without a lowercase 'x'.

Common situations: Shell scripts using a locale/keyboard that yields a different separator; users typing the size with a space or comma out of habit; copying dimensions from a UI that formats as "120 × 40"; forgetting the rows entirely.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/6f802fd82a9b2afc. Report an issue: GitHub.