{"record":{"id":"c7021175961367f9","repo":"tonhowtf/omniget","slug":"arquivo-invalido","errorCode":null,"errorMessage":"arquivo invalido","messagePattern":"arquivo invalido","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/startup.rs","lineNumber":508,"sourceCode":"                path: unit.to_string(),\n                enabled: state == \"enabled\",\n                can_toggle: true,\n            });\n        }\n    }\n    out\n}\n\nasync fn linux_set(item: &StartupItem, enabled: bool) -> anyhow::Result<()> {\n    match item.source.as_str() {\n        \"autostart\" => {\n            let user_dir = dirs::config_dir()\n                .unwrap_or_else(|| home().join(\".config\"))\n                .join(\"autostart\");\n            std::fs::create_dir_all(&user_dir)?;\n            let file = Path::new(&item.path)\n                .file_name()\n                .ok_or_else(|| anyhow!(\"arquivo invalido\"))?;\n            let target = user_dir.join(file);\n            let mut text = std::fs::read_to_string(&item.path).unwrap_or_default();\n            let mut lines: Vec<String> = text\n                .lines()\n                .filter(|l| {\n                    !l.starts_with(\"Hidden=\") && !l.starts_with(\"X-GNOME-Autostart-enabled=\")\n                })\n                .map(String::from)\n                .collect();\n            if !enabled {\n                lines.push(\"Hidden=true\".into());\n                lines.push(\"X-GNOME-Autostart-enabled=false\".into());\n            }\n            text = lines.join(\"\\n\") + \"\\n\";\n            std::fs::write(&target, text)?;\n            Ok(())\n        }\n        \"systemd-user\" => {","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/startup.rs#L490-L526","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nstd::fs::create_dir_all(&user_dir)?;\nlet file = Path::new(&item.path)\n    .file_name()\n    .ok_or_else(|| anyhow!(\"arquivo invalido\"))?;\n\n// after\nif item.path.trim().is_empty() {\n    return Err(anyhow!(\"caminho do item vazio\"));\n}\nstd::fs::create_dir_all(&user_dir)?;\nlet file = Path::new(&item.path)\n    .file_name()\n    .ok_or_else(|| anyhow!(\"arquivo invalido: {}\", item.path))?","handlingStrategy":"validation","validationCode":"fn is_togglable_path(path: &str) -> bool {\n    !path.trim().is_empty() && std::path::Path::new(path).file_name().is_some()\n}\n// call before set_enabled: assert!(is_togglable_path(&item.path));","typeGuard":"fn valid_file_path(p: &str) -> Option<&std::path::Path> {\n    let pt = std::path::Path::new(p);\n    pt.file_name().map(|_| pt)\n}","tryCatchPattern":"match startup::set_enabled(&item, true).await {\n    Err(e) if e.to_string().contains(\"arquivo invalido\") => {\n        eprintln!(\"caminho sem nome de arquivo valido: {}\", item.path);\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["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"],"tags":["linux","filesystem","path","startup-items"],"backgroundTag":"invalid-argument-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}