tonhowtf/omniget · error
File not found
Error message
File not found: {} What it means
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.
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
Example fix
// before
p2p::start_send(PathBuf::from("recording.mp4"), token).await?;
// after
let path = std::fs::canonicalize("recording.mp4")?;
p2p::start_send(path, token).await?; Defensive patterns
Strategy: validation
Validate before calling
async fn can_send(path: &std::path::Path) -> Result<(), String> {
match tokio::fs::metadata(path).await {
Ok(m) if m.is_file() => Ok(()),
Ok(_) => Err("path is not a regular file".into()),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Err(format!("file does not exist: {}", path.display())),
Err(e) => Err(format!("cannot stat file: {e}")),
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- Path is not a file
- Path is not a file
- Failed to move into place
- Failed to replace
- Write error (disk full?)
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/575b1ab1a37c8c09.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/platforms/p2p.rs:216
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 = super::p2p_words::generate_code();
tracing::info!("[p2p] share code generated: {}", code);
Ok(P2pSendSession {
code,
file_path,View on GitHub (pinned to 8600b91f42)