{"record":{"id":"a14b8837d44e5634","repo":"LGUG2Z/komorebi","slug":"unable-to-obtain-user-s-home-folder","errorCode":null,"errorMessage":"unable to obtain user's home folder","messagePattern":"unable to obtain user's home folder","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"komorebic/src/main.rs","lineNumber":1595,"sourceCode":"    GenerateStaticConfig,\n    /// Generates the komorebi.lnk shortcut in shell:startup to autostart komorebi\n    EnableAutostart(EnableAutostart),\n    /// Deletes the komorebi.lnk shortcut in shell:startup to disable autostart\n    DisableAutostart,\n}\n\n// print_query is a helper that queries komorebi and prints the response.\n// panics on error.\nfn print_query(message: &SocketMessage) {\n    match send_query(message) {\n        Ok(response) => println!(\"{response}\"),\n        Err(error) => panic!(\"{}\", error),\n    }\n}\n\nfn startup_dir() -> eyre::Result<PathBuf> {\n    let startup = dirs::home_dir()\n        .expect(\"unable to obtain user's home folder\")\n        .join(\"AppData\")\n        .join(\"Roaming\")\n        .join(\"Microsoft\")\n        .join(\"Windows\")\n        .join(\"Start Menu\")\n        .join(\"Programs\")\n        .join(\"Startup\");\n\n    if !startup.is_dir() {\n        std::fs::create_dir_all(&startup)?;\n    }\n\n    Ok(startup)\n}\n\n#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]\nfn main() -> eyre::Result<()> {\n    let opts: Opts = Opts::parse();","sourceCodeStart":1577,"sourceCodeEnd":1613,"githubUrl":"https://github.com/LGUG2Z/komorebi/blob/e0709f02bfae4e503bf4640f58ee75ecbbfdbb97/komorebic/src/main.rs#L1577-L1613","documentation":"startup_dir() builds the Windows Start Menu Startup folder path by joining fixed AppData segments onto dirs::home_dir(). If the home directory cannot be resolved, it panics with 'unable to obtain user's home folder'. This is used when creating the komorebi.lnk startup shortcut (komorebic startup / enable autostart).","triggerScenarios":"Calling any komorebic command that touches the startup shortcut (e.g. 'komorebic startup install') while dirs::home_dir() returns None because USERPROFILE/HOME is missing.","commonSituations":"Installing the komorebi autostart shortcut from a service account, CI job, or environment with no USERPROFILE; running under a broken Windows profile without Roaming AppData.","solutions":["Run the command from an interactive user session where USERPROFILE is set","Set USERPROFILE (or HOME) manually in the launching environment","Create the Startup folder manually if the profile is incomplete and skip shortcut installation","Verify the Windows profile AppData\\Roaming structure exists"],"exampleFix":"// before\nkomorebic startup install\n// after (ensure home resolves first)\nset USERPROFILE=C:\\Users\\me\nkomorebic startup install","handlingStrategy":"try-catch","validationCode":"# PowerShell guard before installing the startup shortcut\nif (-not $env:USERPROFILE -or -not (Test-Path \"$env:USERPROFILE\\AppData\\Roaming\")) {\n  throw \"User profile/Roaming unavailable; autostart install would panic\"\n}","typeGuard":null,"tryCatchPattern":"// Wrap the invocation and fall back to manual shortcut creation\nmatch run_komorebic(\"startup install\") {\n    Err(e) if e.contains(\"home folder\") => create_startup_shortcut_manually(),\n    other => other,\n}","preventionTips":["Install autostart from a logged-in user session","Ensure USERPROFILE is set when invoking from scripts","Verify AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup exists","Create the .lnk manually if the profile is incomplete"],"tags":["rust","windows","environment","startup"],"backgroundTag":"missing-env-var","analyzedSha":"e0709f02bfae4e503bf4640f58ee75ecbbfdbb97","analyzedAt":"2026-09-06T07:08:05.107Z","contentChangedAt":"2026-09-06T07:08:05.107Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}