tonhowtf/omniget · error · anyhow::Error
arquivo invalido
Error message
arquivo invalido
What it means
In `linux_set` (startup.rs), when enabling/disabling a startup item on Linux, the code derives the destination filename from `item.path` via `Path::file_name()`. If `item.path` has no final path component (e.g. it is empty, "/", ".", "..", or ends in a trailing slash pointing at a directory), `file_name()` returns None and this anyhow error is thrown. It guards the autostart .desktop file creation path.
Solutions
- Validate `item.path` before calling `set_enabled`: reject empty strings and paths with no final component.
- Fix the source data so `item.path` points to a real file (e.g. `/usr/bin/app`), not a directory or slash-terminated path.
- If the path legitimately ends in '/', trim the trailing separator first, then confirm `Path::new(&p).file_name().is_some()`.
- Set `can_toggle = false` in `list()` for items whose path is unusable so `set_enabled` fails earlier with a clearer error (687).
Example fix
// before
std::fs::create_dir_all(&user_dir)?;
let file = Path::new(&item.path)
.file_name()
.ok_or_else(|| anyhow!("arquivo invalido"))?;
// after
if item.path.trim().is_empty() {
return Err(anyhow!("caminho do item vazio"));
}
std::fs::create_dir_all(&user_dir)?;
let file = Path::new(&item.path)
.file_name()
.ok_or_else(|| anyhow!("arquivo invalido: {}", item.path))? Defensive patterns
Strategy: validation
Validate before calling
fn is_togglable_path(path: &str) -> bool {
!path.trim().is_empty() && std::path::Path::new(path).file_name().is_some()
}
// call before set_enabled: assert!(is_togglable_path(&item.path)); Type guard
fn valid_file_path(p: &str) -> Option<&std::path::Path> {
let pt = std::path::Path::new(p);
pt.file_name().map(|_| pt)
} Try / catch
match startup::set_enabled(&item, true).await {
Err(e) if e.to_string().contains("arquivo invalido") => {
eprintln!("caminho sem nome de arquivo valido: {}", item.path);
}
Err(e) => return Err(e),
Ok(()) => {}
} Prevention
- Never store slash-terminated or empty paths in StartupItem records
- Canonicalize paths at ingest time (list()) so file_name() is always available
- Mark items with unusable paths as can_toggle=false during listing
When it happens
Trigger: Calling `set_enabled(item, true)` on Linux (mac_set/linux branch of linux_set) with a StartupItem whose `path` is an empty string, a bare directory path like "/usr/bin/", "/", ".", or ".." — any path for which `Path::file_name()` yields None.
Common situations: Database/config records for startup items with missing or truncated `path` fields; paths built by string concatenation that end with a separator; items whose executable was uninstalled leaving a directory path; deserialized entries where `path` was never populated.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Path is not a file: {}
- Path is not a file: {}
- nao achei o caminho do export: {}
- não achei {}
- File not found: {}
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/c7021175961367f9.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/startup.rs:508
path: unit.to_string(),
enabled: state == "enabled",
can_toggle: true,
});
}
}
out
}
async fn linux_set(item: &StartupItem, enabled: bool) -> anyhow::Result<()> {
match item.source.as_str() {
"autostart" => {
let user_dir = dirs::config_dir()
.unwrap_or_else(|| home().join(".config"))
.join("autostart");
std::fs::create_dir_all(&user_dir)?;
let file = Path::new(&item.path)
.file_name()
.ok_or_else(|| anyhow!("arquivo invalido"))?;
let target = user_dir.join(file);
let mut text = std::fs::read_to_string(&item.path).unwrap_or_default();
let mut lines: Vec<String> = text
.lines()
.filter(|l| {
!l.starts_with("Hidden=") && !l.starts_with("X-GNOME-Autostart-enabled=")
})
.map(String::from)
.collect();
if !enabled {
lines.push("Hidden=true".into());
lines.push("X-GNOME-Autostart-enabled=false".into());
}
text = lines.join("\n") + "\n";
std::fs::write(&target, text)?;
Ok(())
}
"systemd-user" => {View on GitHub (pinned to 8600b91f42)