{"record":{"id":"779164773856219c","repo":"tonhowtf/omniget","slug":"invalid-file-size-from-sender","errorCode":null,"errorMessage":"Invalid file size from sender: {}","messagePattern":"Invalid file size from sender: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/p2p.rs","lineNumber":142,"sourceCode":"\n        write_half\n            .write_all(format!(\"RECV {}\\n\", code).as_bytes())\n            .await?;\n        write_half.flush().await?;\n\n        let response = read_line(&mut reader).await?;\n        check_relay_error(&response)?;\n        if response != \"READY\" {\n            anyhow::bail!(\"Unexpected relay response: {}\", response);\n        }\n\n        tracing::info!(\"[p2p] connected to sender via relay\");\n\n        let file_name = read_line(&mut reader).await?;\n        let file_size_str = read_line(&mut reader).await?;\n        let file_size: u64 = file_size_str\n            .parse()\n            .map_err(|_| anyhow!(\"Invalid file size from sender: {}\", file_size_str))?;\n\n        tracing::info!(\"[p2p] receiving: {} ({} bytes)\", file_name, file_size);\n\n        write_half.write_all(b\"OK\\n\").await?;\n        write_half.flush().await?;\n\n        let _ = progress.send(ProgressUpdate::percent(0.0)).await;\n\n        let sanitized = sanitize_filename::sanitize(&file_name);\n        let output_path = opts.output_dir.join(&sanitized);\n        if let Some(parent) = output_path.parent() {\n            tokio::fs::create_dir_all(parent).await?;\n        }\n\n        let mut file = File::create(&output_path).await?;\n        let mut received: u64 = 0;\n        let mut buf = vec![0u8; CHUNK_SIZE];\n","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/p2p.rs#L124-L160","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify sender and receiver use the same protocol version (name line, then size line)","Check the sender did not fail before writing metadata (read sender logs)","Confirm the share code matches an active sender session on the relay","Trim whitespace/CR before parsing, and log the raw line to diagnose","Add retry with backoff for transient relay-session mismatches"],"exampleFix":"// before\nlet file_size: u64 = file_size_str.parse()\n    .map_err(|_| anyhow!(\"Invalid file size from sender: {}\", file_size_str))?;\n// after\nlet file_size: u64 = file_size_str.trim().parse().map_err(|_| {\n    anyhow!(\"Invalid file size from sender: {:?} (protocol mismatch or dead sender)\", file_size_str)\n})?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let file_size: u64 = match file_size_str.trim().parse() {\n    Ok(n) => n,\n    Err(_) => {\n        tracing::error!(\"sender sent non-numeric size: {:?}\", file_size_str);\n        return Err(anyhow!(\"protocol mismatch with sender\")); // abort, do not retry blindly\n    }\n};","preventionTips":["Pin sender and receiver to the same app/protocol version","Validate the share code is actively paired before connecting","Log raw wire lines (name/size) on both ends for debugging","Treat parse failure as fatal — the session is desynchronized"],"tags":["p2p","protocol","parsing","network","wire-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}