{"record":{"id":"d7cc04273a10f8c3","repo":"LGUG2Z/komorebi","slug":"there-is-no-home-directory-d7cc04","errorCode":null,"errorMessage":"there is no home directory","messagePattern":"there is no home directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"komorebi-bar/src/main.rs","lineNumber":169,"sourceCode":"        }\n    }\n\n    color_eyre::install()?;\n\n    if std::env::var(\"RUST_LOG\").is_err() {\n        unsafe {\n            std::env::set_var(\"RUST_LOG\", \"info\");\n        }\n    }\n\n    tracing::subscriber::set_global_default(\n        tracing_subscriber::fmt::Subscriber::builder()\n            .with_env_filter(EnvFilter::from_default_env())\n            .finish(),\n    )?;\n\n    let home_dir: PathBuf = std::env::var(\"KOMOREBI_CONFIG_HOME\").map_or_else(\n        |_| dirs::home_dir().expect(\"there is no home directory\"),\n        |home_path| {\n            let home = home_path.replace_env();\n\n            assert!(\n                home.is_dir(),\n                \"$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory\"\n            );\n\n            home\n        },\n    );\n\n    if opts.quickstart {\n        let komorebi_bar_json = include_str!(\"../../docs/komorebi.bar.example.json\").to_string();\n        std::fs::write(home_dir.join(\"komorebi.bar.json\"), komorebi_bar_json)?;\n        println!(\n            \"Example komorebi.bar.json file written to {}\",\n            home_dir.display()","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/LGUG2Z/komorebi/blob/e0709f02bfae4e503bf4640f58ee75ecbbfdbb97/komorebi-bar/src/main.rs#L151-L187","documentation":"In komorebi-bar's `main`, before the bar starts, the config home directory is resolved the same way as in the bar module: `KOMOREBI_CONFIG_HOME` is read, falling back to `dirs::home_dir()` with `.expect(\"there is no home directory\")`. This panics at startup when neither the env var nor the OS home directory can be resolved, preventing the process from starting at all.","triggerScenarios":"Executing the komorebi-bar binary where `KOMOREBI_CONFIG_HOME` is unset and `dirs::home_dir()` returns None — i.e. `USERPROFILE`/`HOME` absent from the process environment at process start.","commonSituations":"Starting the bar from a stripped-environment context (Windows service, scheduled task, SSH session without a profile), CI/container runs with no USERPROFILE, or a corrupted user profile so the home dir lookup fails.","solutions":["Set `KOMOREBI_CONFIG_HOME` to a valid directory before invoking the binary (e.g. `$Env:KOMOREBI_CONFIG_HOME = \"$Env:USERPROFILE\\.config\\komorebi\"`).","Ensure `USERPROFILE` (Windows) or `HOME` (Unix) is present and correct in the launching environment.","Launch the bar from a regular user shell / via the documented komorebi startup path rather than a bare service context.","Library-side: return a startup error instead of an expect panic so users get an actionable message."],"exampleFix":"// before\nlet home_dir: PathBuf = std::env::var(\"KOMOREBI_CONFIG_HOME\").map_or_else(\n    |_| dirs::home_dir().expect(\"there is no home directory\"),\n    |home_path| { /* ... */ },\n);\n// after\nlet home_dir: PathBuf = std::env::var(\"KOMOREBI_CONFIG_HOME\").map_or_else(\n    |_| dirs::home_dir().ok_or_else(|| {\n        anyhow!(\"there is no home directory; set KOMOREBI_CONFIG_HOME to your komorebi config directory\")\n    })?,\n    |home_path| { /* ... */ },\n);","handlingStrategy":"try-catch","validationCode":"// check before invoking the binary (PowerShell)\nif (-not $Env:KOMOREBI_CONFIG_HOME -and -not $Env:USERPROFILE) {\n    throw \"No home directory resolvable: set KOMOREBI_CONFIG_HOME or USERPROFILE\"\n}","typeGuard":"fn has_resolvable_home() -> bool {\n    std::env::var_os(\"KOMOREBI_CONFIG_HOME\").is_some() || dirs::home_dir().is_some()\n}","tryCatchPattern":"# launch wrapper that supplies a fallback home\nif (-not $Env:KOMOREBI_CONFIG_HOME) {\n    if (-not $Env:USERPROFILE) { throw \"USERPROFILE missing; cannot start komorebi-bar\" }\n    $Env:KOMOREBI_CONFIG_HOME = \"$Env:USERPROFILE\\.config\\komorebi\"\n}\n& komorebi-bar","preventionTips":["Export KOMOREBI_CONFIG_HOME in every environment that can start the bar (profile, service definition, task scheduler action).","Run the bar from a normal login shell so USERPROFILE is populated.","Add a startup env check to any wrapper script around komorebi-bar.","In containers/CI, explicitly set HOME before invoking the binary."],"tags":["rust","panic","startup","environment","home-directory"],"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-14T00:17:10.932Z"}