tonhowtf/omniget · error

Invalid file size from sender

Error message

Invalid file size from sender: {}

What it means

After connecting, the receiver reads the sender's handshake lines (file name, then file size) and parses the size as u64. If the sender sent a line that is not a valid unsigned integer (or empty/garbage), parse() fails and this error is thrown. It protects against protocol desync between sender and receiver.

Solutions

  1. Verify sender writes the size as a plain decimal u64 followed by a single newline.
  2. Trim the received line (especially '\r') before parsing: file_size_str.trim().parse::<u64>().
  3. Check that sender/receiver protocol versions match (same handshake order and format).
  4. Inspect what the sender actually sent — log file_size_str verbatim to spot protocol desync.

Example fix

// before
let file_size: u64 = file_size_str
    .parse()
    .map_err(|_| anyhow!("Invalid file size from sender: {}", file_size_str))?;
// after
let file_size: u64 = file_size_str
    .trim()
    .parse()
    .map_err(|_| anyhow!("Invalid file size from sender: {:?}", file_size_str))?;
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust: validate a size line before handing it to the protocol
fn parse_size_line(line: &str) -> Option<u64> {
    line.trim().parse::<u64>().ok()
}

Try / catch

let file_size: u64 = match read_line(&mut reader).await?.trim().parse() {
    Ok(n) => n,
    Err(_) => {
        tracing::error!("sender handshake desync, got: {:?}", file_size_str);
        anyhow::bail!("sender sent invalid file size; transfer aborted");
    }
};

Prevention

When it happens

Trigger: download()'s read_line returns a file_size_str that fails u64::parse — sender sent an error message, an empty line, a line with trailing characters (e.g. '\r' handled incorrectly), or the protocol is out of order so a non-size line is read here.

Common situations: Sender aborted and the relay delivered a status/error line instead of the size; sender implementation version mismatch writing a human-readable size (e.g. '1.5 MB'); CRLF line endings not trimmed before parse.

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 tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/9e990c35aa83ef33. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/platforms/p2p/mod.rs:144

        write_half
            .write_all(format!("RECV {}\n", code).as_bytes())
            .await?;
        write_half.flush().await?;

        let response = read_line(&mut reader).await?;
        check_relay_error(&response)?;
        if response != "READY" {
            anyhow::bail!("Unexpected relay response: {}", response);
        }

        tracing::info!("[p2p] connected to sender via relay");

        let file_name = read_line(&mut reader).await?;
        let file_size_str = read_line(&mut reader).await?;
        let file_size: u64 = file_size_str
            .parse()
            .map_err(|_| anyhow!("Invalid file size from sender: {}", file_size_str))?;

        tracing::info!("[p2p] receiving: {} ({} bytes)", file_name, file_size);

        write_half.write_all(b"OK\n").await?;
        write_half.flush().await?;

        let _ = progress.send(ProgressUpdate::percent(0.0)).await;

        let sanitized = sanitize_filename::sanitize(&file_name);
        let output_path = opts.output_dir.join(&sanitized);
        if let Some(parent) = output_path.parent() {
            tokio::fs::create_dir_all(parent).await?;
        }

        let mut file = File::create(&output_path).await?;
        let mut received: u64 = 0;
        let mut buf = vec![0u8; CHUNK_SIZE];

View on GitHub (pinned to 8600b91f42)