tonhowtf/omniget · error
Path is not a file
Error message
Path is not a file: {} What it means
start_send() first calls tokio::fs::metadata on the given path; if the metadata succeeds but is_file() is false, the path is a directory/symlink-to-dir/device, and start_send bails with this message. The library only transfers regular files.
Solutions
- Validate the path is a regular file before calling start_send (fs::metadata(path)?.is_file()).
- If a directory was intended, enumerate its files and send them individually or as an archive.
- Resolve symlinks with tokio::fs::canonicalize first so the check reflects the target's type.
- Improve the UI to reject folders at selection time.
Example fix
// before
start_send(dir_path.into()).await?;
// after
let md = tokio::fs::metadata(&path).await?;
if !md.is_file() {
anyhow::bail!("Please select a regular file, not a directory: {}", path.display());
}
start_send(path).await?; Defensive patterns
Strategy: validation
Validate before calling
let md = tokio::fs::metadata(&path).await?;
anyhow::ensure!(md.is_file(), "{} is not a regular file", path.display()); Type guard
fn is_regular_file(path: &std::path::Path) -> bool {
std::fs::metadata(path).map(|m| m.is_file()).unwrap_or(false)
} Try / catch
if let Err(e) = start_send(path.clone()).await {
if e.to_string().contains("Path is not a file") {
ui.show_warning("Select a file, not a folder");
} else { return Err(e); }
} Prevention
- Use a file picker (not a free-text path field) so users can't select directories.
- Canonicalize paths before validation to resolve symlinks.
- Validate is_file() in the UI layer before invoking the Tauri command.
- Special-case folders: offer to zip/enumerate instead of failing.
When it happens
Trigger: Calling start_send with a directory path, a special file (/dev/*, named pipe), or a path that exists but is not a regular file.
Common situations: User drags a folder into the send UI, a symlink points to a directory, or a path built from string concatenation accidentally resolves to a directory.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/e684e2f3e14bca62.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/src/platforms/p2p/mod.rs:221
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,
file_name,
file_size,
cancel_token,View on GitHub (pinned to 8600b91f42)