{"record":{"id":"575b1ab1a37c8c09","repo":"tonhowtf/omniget","slug":"file-not-found","errorCode":null,"errorMessage":"File not found: {}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/p2p.rs","lineNumber":216,"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 = super::p2p_words::generate_code();\n\n    tracing::info!(\"[p2p] share code generated: {}\", code);\n\n    Ok(P2pSendSession {\n        code,\n        file_path,","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/p2p.rs#L198-L234","documentation":"start_send() first calls tokio::fs::metadata on the given path; if the filesystem lookup fails (typically NotFound), the OS error is wrapped as 'File not found: {}'. This is the entry point for the sender side of a P2P transfer, so a bad path aborts before a session is created.","triggerScenarios":"Calling start_send with a PathBuf that does not exist, was deleted/moved before the call, or is inaccessible due to permissions or path-encoding issues.","commonSituations":"User picks a file then it's moved/deleted before sending; relative path resolved against a different working directory; typo'd path from CLI args; sandboxed app lacks access to the path.","solutions":["Check the path exists (fs::metadata / Path::exists) before calling start_send","Use absolute, canonicalized paths (fs::canonicalize) instead of relative ones","Verify the process has read permission for the file and its directories","Handle the OS error code (NotFound vs PermissionDenied) to give the user an accurate message"],"exampleFix":"// before\np2p::start_send(PathBuf::from(\"recording.mp4\"), token).await?;\n// after\nlet path = std::fs::canonicalize(\"recording.mp4\")?;\np2p::start_send(path, token).await?;","handlingStrategy":"validation","validationCode":"async fn can_send(path: &std::path::Path) -> Result<(), String> {\n    match tokio::fs::metadata(path).await {\n        Ok(m) if m.is_file() => Ok(()),\n        Ok(_) => Err(\"path is not a regular file\".into()),\n        Err(e) if e.kind() == std::io::ErrorKind::NotFound => Err(format!(\"file does not exist: {}\", path.display())),\n        Err(e) => Err(format!(\"cannot stat file: {e}\")),\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Canonicalize paths before sending","Re-stat the file right before start_send if the user selected it earlier","Check file permissions in sandboxed environments","Map io::ErrorKind to precise user messages"],"tags":["filesystem","p2p","path","io"],"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"}