tonhowtf/omniget · error

File not found

Error message

File not found: {}

What it means

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.

Solutions

  1. Verify the path exists before calling start_send (tokio::fs::try_exists or std::path exists()).
  2. Use absolute paths when constructing file_path; resolve relative paths against the intended base directory.
  3. If the path came from UI/file picker state, refresh/validate it at send time and surface a user-facing 'file missing' prompt.
  4. Check file permissions if the file exists but the stat fails (EACCES also lands here).

Example fix

// before
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))?;
// after
pub async fn start_send(file_path: PathBuf, cancel_token: CancellationToken) -> anyhow::Result<P2pSendSession> {
    if !file_path.exists() {
        anyhow::bail!("File not found: {}", file_path.display());
    }
    let metadata = tokio::fs::metadata(&file_path).await
        .map_err(|e| anyhow!("Cannot stat file {}: {}", file_path.display(), e))?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: check the file before starting a send session
async fn ensure_sendable(path: &Path) -> anyhow::Result<()> {
    let meta = tokio::fs::metadata(path).await
        .map_err(|e| anyhow!("Cannot access {}: {}", path.display(), e))?;
    if !meta.is_file() {
        anyhow::bail!("{} is not a regular file", path.display());
    }
    Ok(())
}

Try / catch

match start_send(path, token).await {
    Err(e) if e.to_string().starts_with("File not found") => {
        ui.show_error(format!("The file {} is no longer available", path.display()));
    }
    other => other?,
}

Prevention

When it happens

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

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

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/src/platforms/p2p/mod.rs:218

pub struct P2pSendSession {
    pub code: String,
    pub file_path: PathBuf,
    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 = words::generate_code();

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

    Ok(P2pSendSession {
        code,
        file_path,

View on GitHub (pinned to 8600b91f42)