{"record":{"id":"afdae8f8e03f75bd","repo":"tonhowtf/omniget","slug":"caminho-do-item-de-login-desconhecido","errorCode":null,"errorMessage":"caminho do item de login desconhecido","messagePattern":"caminho do item de login desconhecido","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/startup.rs","lineNumber":247,"sourceCode":"                .await;\n                run(\n                    \"launchctl\",\n                    &[\"disable\", &format!(\"{}/{}\", target, item.name)],\n                )\n                .await?;\n            }\n            Ok(())\n        }\n        \"login-item\" => {\n            let mut removed = removed_login_items();\n            if enabled {\n                let path = removed\n                    .iter()\n                    .find(|(n, _)| *n == item.name)\n                    .map(|(_, p)| p.clone())\n                    .unwrap_or_else(|| item.path.clone());\n                if path.is_empty() {\n                    return Err(anyhow!(\"caminho do item de login desconhecido\"));\n                }\n                run(\"osascript\", &[\"-e\", &format!(\"tell application \\\"System Events\\\" to make login item at end with properties {{path:\\\"{}\\\", hidden:false}}\", path.replace('\"', \"\\\\\\\"\"))]).await?;\n                removed.retain(|(n, _)| *n != item.name);\n            } else {\n                run(\n                    \"osascript\",\n                    &[\n                        \"-e\",\n                        &format!(\n                            \"tell application \\\"System Events\\\" to delete login item \\\"{}\\\"\",\n                            item.name.replace('\"', \"\\\\\\\"\")\n                        ),\n                    ],\n                )\n                .await?;\n                removed.retain(|(n, _)| *n != item.name);\n                removed.push((item.name.clone(), item.path.clone()));\n            }","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/startup.rs#L229-L265","documentation":"In mac_set, when disabling a login item the code first removes the existing login item and then re-adds it with the same path. To re-add it, it looks up the item's path either from the 'removed' list recorded earlier in the call or from item.path; if both are empty it cannot reconstruct the path and throws this error instead of creating a login item with an invalid empty path.","triggerScenarios":"Calling set_enabled(item, false) for a macOS login-item whose 'path' field is empty and whose name does not match any entry captured in the removed list — e.g. an item enumerated with a blank path, or a name that changed between listing and the disable call.","commonSituations":"Startup items discovered via System Events that report only a name (no resolved path); stale UI state where the item list was refreshed and names no longer match; items added by the app bundle whose path metadata was never persisted; corrupt/legacy persisted startup-item records with empty paths.","solutions":["Ensure items returned by mac_items always populate 'path' (resolve via System Events properties or the app bundle path) before allowing enable/disable in the UI","Refresh the item list immediately before calling set_enabled so names/paths are in sync","When path is empty, re-enumerate login items via osascript to recover the real path instead of failing","Skip or warn on items without a resolvable path rather than attempting the remove/re-add cycle","Persist the resolved path with each item so later set_enabled calls always have it"],"exampleFix":"// before\nlet path = removed.iter().find(|(n, _)| *n == item.name)\n    .map(|(_, p)| p.clone())\n    .unwrap_or_else(|| item.path.clone());\nif path.is_empty() {\n    return Err(anyhow!(\"caminho do item de login desconhecido\"));\n}\n// after: recover the path from a fresh System Events query before failing\nlet path = removed.iter().find(|(n, _)| *n == item.name)\n    .map(|(_, p)| p.clone())\n    .filter(|p| !p.is_empty())\n    .or_else(|| item.path.clone().into_option_if_non_empty())\n    .or_else(|| resolve_login_item_path(&item.name));\nlet Some(path) = path else {\n    return Err(anyhow!(\"caminho do item de login desconhecido para '{}'\", item.name));\n};","handlingStrategy":"validation","validationCode":"// Refuse to toggle items without a resolvable path\nfn can_toggle(item: &StartupItem) -> bool {\n    !item.name.is_empty() && !item.path.is_empty()\n}\nif !can_toggle(&item) {\n    // resolve or re-enumerate before calling set_enabled\n    item = refresh_item_path(item)?;\n}","typeGuard":"fn has_resolvable_path(item: &StartupItem) -> bool {\n    !item.path.trim().is_empty()\n}","tryCatchPattern":"match set_enabled(item, false).await {\n    Ok(_) => refresh_items(),\n    Err(e) if e.to_string().contains(\"caminho do item de login desconhecido\") => {\n        // re-enumerate login items to recover the path, then retry once\n        let items = mac_items().await?;\n        set_enabled(items.iter().find(|i| i.name == item.name).unwrap(), false).await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always resolve and persist the full path when listing macOS login items","Refresh the item list immediately before toggling so names/paths match","Validate item.path is non-empty in the UI before enabling the toggle","Escape quotes in item names/paths before interpolating into AppleScript"],"tags":["macos","login-items","rust","state"],"backgroundTag":"empty-required-field","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"}