tonhowtf/omniget · error

Path is not a file

Error message

Path is not a file: {}

What it means

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.

Solutions

  1. Check tokio::fs::metadata(path).is_file() before calling start_send and show a folder-picking error in the UI
  2. Use a file picker (not a directory picker) to obtain file_path
  3. If sending a whole directory is intended, zip/tar it into a single file first

Example fix

// before
let session = p2p::start_send(PathBuf::from("/home/user/Downloads")).await?;
// after
let path = PathBuf::from("/home/user/Downloads/report.pdf");
let meta = tokio::fs::metadata(&path).await?;
if !meta.is_file() {
    anyhow::bail!("Please select a regular file, not a directory");
}
let session = p2p::start_send(path).await?;
Defensive patterns

Strategy: validation

Validate before calling

async fn ensure_regular_file(p: &std::path::Path) -> anyhow::Result<()> {
    let m = tokio::fs::metadata(p).await
        .map_err(|e| anyhow::anyhow!("Cannot stat {:?}: {}", p, e))?;
    if !m.is_file() { anyhow::bail!("{:?} is not a regular file", p); }
    Ok(())
}

Type guard

async fn is_sendable_file(p: &std::path::Path) -> bool {
    tokio::fs::metadata(p).await.map(|m| m.is_file()).unwrap_or(false)
}

Try / catch

match p2p::start_send(path.clone()).await {
    Err(e) if e.to_string().starts_with("Path is not a file") => {
        ui.prompt_file_picker(); // let the user pick again
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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".

Common situations: 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.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/4f18bb2759bf4f2c. Report an issue: GitHub.

Appendix: source

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

    pub file_name: String,
    pub file_size: u64,
    pub cancel_token: CancellationToken,
    pub progress: Arc<tokio::sync::Mutex<f64>>,
    pub status: Arc<tokio::sync::Mutex<String>>,
    pub sent_bytes: Arc<tokio::sync::Mutex<u64>>,
    pub paused: Arc<std::sync::atomic::AtomicBool>,
}

pub async fn start_send(
    file_path: PathBuf,
    cancel_token: CancellationToken,
) -> anyhow::Result<P2pSendSession> {
    let metadata = tokio::fs::metadata(&file_path)
        .await
        .map_err(|e| anyhow!("File not found: {}", e))?;

    if !metadata.is_file() {
        anyhow::bail!("Path is not a file: {}", file_path.display());
    }

    let file_size = metadata.len();
    let file_name = file_path
        .file_name()
        .map(|n| n.to_string_lossy().to_string())
        .unwrap_or_else(|| "file".to_string());

    let code = super::p2p_words::generate_code();

    tracing::info!("[p2p] share code generated: {}", code);

    Ok(P2pSendSession {
        code,
        file_path,
        file_name,
        file_size,
        cancel_token,

View on GitHub (pinned to 8600b91f42)