tonhowtf/omniget · error

Invalid file size from sender

Error message

Invalid file size from sender: {}

What it means

After connecting through the relay, the receiver expects the sender's second line to be the file size as a decimal u64. If that line cannot be parsed, this error reports the raw text received. It indicates a protocol violation or desynchronization between sender and receiver.

Solutions

  1. Verify sender and receiver use the same protocol version (name line, then size line)
  2. Check the sender did not fail before writing metadata (read sender logs)
  3. Confirm the share code matches an active sender session on the relay
  4. Trim whitespace/CR before parsing, and log the raw line to diagnose
  5. Add retry with backoff for transient relay-session mismatches

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: {:?} (protocol mismatch or dead sender)", file_size_str)
})?;
Defensive patterns

Strategy: try-catch

Try / catch

let file_size: u64 = match file_size_str.trim().parse() {
    Ok(n) => n,
    Err(_) => {
        tracing::error!("sender sent non-numeric size: {:?}", file_size_str);
        return Err(anyhow!("protocol mismatch with sender")); // abort, do not retry blindly
    }
};

Prevention

When it happens

Trigger: The line read after the file-name line is not a valid u64 (e.g. empty line, an error message, an 'OK'/'ERR' status reply, or garbage from a non-sender peer occupying the relay slot).

Common situations: Sender crashed or sent an error text instead of metadata; receiver connected to a stale/mismatched relay session; protocol version mismatch where the sender sends fields in a different order; connecting before the sender has written metadata.

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/779164773856219c. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/p2p.rs:142

        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)