{"record":{"id":"b48efa6b263797a9","repo":"tonhowtf/omniget","slug":"file-not-found-mod","errorCode":null,"errorMessage":"File not found: {}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/platforms/p2p/mod.rs","lineNumber":218,"sourceCode":"pub struct P2pSendSession {\n    pub code: String,\n    pub file_path: PathBuf,\n    pub file_name: String,\n    pub file_size: u64,\n    pub cancel_token: CancellationToken,\n    pub progress: Arc<tokio::sync::Mutex<f64>>,\n    pub status: Arc<tokio::sync::Mutex<String>>,\n    pub sent_bytes: Arc<tokio::sync::Mutex<u64>>,\n    pub paused: Arc<std::sync::atomic::AtomicBool>,\n}\n\npub async fn start_send(\n    file_path: PathBuf,\n    cancel_token: CancellationToken,\n) -> anyhow::Result<P2pSendSession> {\n    let metadata = tokio::fs::metadata(&file_path)\n        .await\n        .map_err(|e| anyhow!(\"File not found: {}\", e))?;\n\n    if !metadata.is_file() {\n        anyhow::bail!(\"Path is not a file: {}\", file_path.display());\n    }\n\n    let file_size = metadata.len();\n    let file_name = file_path\n        .file_name()\n        .map(|n| n.to_string_lossy().to_string())\n        .unwrap_or_else(|| \"file\".to_string());\n\n    let code = words::generate_code();\n\n    tracing::info!(\"[p2p] share code generated: {}\", code);\n\n    Ok(P2pSendSession {\n        code,\n        file_path,","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/platforms/p2p/mod.rs#L200-L236","documentation":"start_send is the public entry point for the sender side; it first stats the file with tokio::fs::metadata. If the path cannot be stat'ed (does not exist, or the process lacks permission), the io::Error is wrapped in this 'File not found' error. It is the pre-flight check before the file is offered over P2P.","triggerScenarios":"start_send(file_path, cancel_token) is called with a path that does not exist, was moved/deleted after being selected, is on an unmounted volume, or the process lacks read permission on the parent directory.","commonSituations":"User picks a file then deletes/renames it before sending; relative path resolved against a different working directory; stale path from a previous session; temporary file already cleaned up.","solutions":["Verify the path exists before calling start_send (tokio::fs::try_exists or std::path exists()).","Use absolute paths when constructing file_path; resolve relative paths against the intended base directory.","If the path came from UI/file picker state, refresh/validate it at send time and surface a user-facing 'file missing' prompt.","Check file permissions if the file exists but the stat fails (EACCES also lands here)."],"exampleFix":"// before\npub async fn start_send(file_path: PathBuf, cancel_token: CancellationToken) -> anyhow::Result<P2pSendSession> {\n    let metadata = tokio::fs::metadata(&file_path).await\n        .map_err(|e| anyhow!(\"File not found: {}\", e))?;\n// after\npub async fn start_send(file_path: PathBuf, cancel_token: CancellationToken) -> anyhow::Result<P2pSendSession> {\n    if !file_path.exists() {\n        anyhow::bail!(\"File not found: {}\", file_path.display());\n    }\n    let metadata = tokio::fs::metadata(&file_path).await\n        .map_err(|e| anyhow!(\"Cannot stat file {}: {}\", file_path.display(), e))?;","handlingStrategy":"validation","validationCode":"// Rust: check the file before starting a send session\nasync fn ensure_sendable(path: &Path) -> anyhow::Result<()> {\n    let meta = tokio::fs::metadata(path).await\n        .map_err(|e| anyhow!(\"Cannot access {}: {}\", path.display(), e))?;\n    if !meta.is_file() {\n        anyhow::bail!(\"{} is not a regular file\", path.display());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match start_send(path, token).await {\n    Err(e) if e.to_string().starts_with(\"File not found\") => {\n        ui.show_error(format!(\"The file {} is no longer available\", path.display()));\n    }\n    other => other?,\n}","preventionTips":["Validate file existence at UI selection time AND immediately before sending","Resolve picked files to canonical absolute paths up front","Hold an open file handle (or re-stat) if the send may start long after selection","Handle rename/move events for files queued for sending"],"tags":["filesystem","p2p","file","validation"],"backgroundTag":"file-not-found","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}