{"record":{"id":"4f18bb2759bf4f2c","repo":"tonhowtf/omniget","slug":"path-is-not-a-file","errorCode":null,"errorMessage":"Path is not a file: {}","messagePattern":"Path is not a file: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/p2p.rs","lineNumber":219,"sourceCode":"    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,\n        file_name,\n        file_size,\n        cancel_token,","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/p2p.rs#L201-L237","documentation":"start_send validates the file_path with tokio::fs::metadata and rejects anything that exists but is not a regular file — directories, sockets, fifos, device nodes. Directories are the overwhelmingly common case: a user selected a folder instead of a file.","triggerScenarios":"Calling start_send() with a path that exists on disk but is a directory (or special file) rather than a regular file. Paths that don't exist at all fail earlier with \"File not found\".","commonSituations":"Drag-and-drop of a folder into a send UI; a config pointing at a directory like ~/Downloads; platform-specific special paths (/dev/*, named pipes) passed by mistake.","solutions":["Check tokio::fs::metadata(path).is_file() before calling start_send and show a folder-picking error in the UI","Use a file picker (not a directory picker) to obtain file_path","If sending a whole directory is intended, zip/tar it into a single file first"],"exampleFix":"// before\nlet session = p2p::start_send(PathBuf::from(\"/home/user/Downloads\")).await?;\n// after\nlet path = PathBuf::from(\"/home/user/Downloads/report.pdf\");\nlet meta = tokio::fs::metadata(&path).await?;\nif !meta.is_file() {\n    anyhow::bail!(\"Please select a regular file, not a directory\");\n}\nlet session = p2p::start_send(path).await?;","handlingStrategy":"validation","validationCode":"async fn ensure_regular_file(p: &std::path::Path) -> anyhow::Result<()> {\n    let m = tokio::fs::metadata(p).await\n        .map_err(|e| anyhow::anyhow!(\"Cannot stat {:?}: {}\", p, e))?;\n    if !m.is_file() { anyhow::bail!(\"{:?} is not a regular file\", p); }\n    Ok(())\n}","typeGuard":"async fn is_sendable_file(p: &std::path::Path) -> bool {\n    tokio::fs::metadata(p).await.map(|m| m.is_file()).unwrap_or(false)\n}","tryCatchPattern":"match p2p::start_send(path.clone()).await {\n    Err(e) if e.to_string().starts_with(\"Path is not a file\") => {\n        ui.prompt_file_picker(); // let the user pick again\n    }\n    other => other?,\n}","preventionTips":["Use file pickers, not text inputs, for send paths","Zip directories before offering them for send","Validate path existence and kind in UI state before invoking start_send"],"tags":["p2p","filesystem","validation","path"],"backgroundTag":"path-is-not-a-directory","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"}