LGUG2Z/komorebi · error

could not find home dir

Error message

could not find home dir

What it means

When printing status/configuration diagnostics, komorebic falls back to dirs::home_dir() to display the default config location when no KOMOREBI_CONFIG_HOME is set. It panics with 'could not find home dir' when the OS home directory cannot be resolved in that fallback path.

Source

Thrown at komorebic/src/main.rs:1883

            println!("in order for the autostart command to work properly");
        }
        SubCommand::DisableAutostart => {
            let startup_dir = startup_dir()?;
            let shortcut_file = startup_dir.join("komorebi.lnk");

            if shortcut_file.is_file() {
                std::fs::remove_file(shortcut_file)?;
            }
        }
        SubCommand::Check(args) => {
            let home_display = HOME_DIR.display();
            if HAS_CUSTOM_CONFIG_HOME.load(Ordering::SeqCst) {
                println!("KOMOREBI_CONFIG_HOME detected: {home_display}\n");
            } else {
                println!(
                    "No KOMOREBI_CONFIG_HOME detected, defaulting to {}\n",
                    dirs::home_dir()
                        .expect("could not find home dir")
                        .to_string_lossy()
                );
            }

            println!("Looking for configuration files in {home_display}\n");

            let static_config = if let Some(static_config) = args.komorebi_config {
                println!(
                    "Using an arbitrary configuration file passed to --komorebi-config flag\n"
                );
                static_config
            } else {
                HOME_DIR.join("komorebi.json")
            };

            let config_pwsh = HOME_DIR.join("komorebi.ps1");
            let config_ahk = HOME_DIR.join("komorebi.ahk");
            let config_whkd = WHKD_CONFIG_DIR.join("whkdrc");

View on GitHub (pinned to e0709f02bf)

Solutions

  1. Set KOMOREBI_CONFIG_HOME so the fallback to home_dir() is never taken
  2. Set USERPROFILE/HOME in the launching environment
  3. Run komorebic from a regular user shell
  4. Restore the missing home directory in the profile

Example fix

// before: diagnostics panic without home
komorebic quickstart
// after
export KOMOREBI_CONFIG_HOME="$HOME/.config/komorebi"
komorebic quickstart
Defensive patterns

Strategy: validation

Validate before calling

# Ensure a home or explicit config home before komorebic diagnostics
if [ -z "$HOME" ] && [ -z "$USERPROFILE" ] && [ -z "$KOMOREBI_CONFIG_HOME" ]; then
  echo 'Set HOME or KOMOREBI_CONFIG_HOME'; exit 1
fi

Prevention

When it happens

Trigger: Running a komorebic command that prints config diagnostics while HAS_CUSTOM_CONFIG_HOME is false (no valid KOMOREBI_CONFIG_HOME) and dirs::home_dir() returns None.

Common situations: Running status/quickstart-like output commands from a service account or environment without USERPROFILE/HOME; containerized runs with an empty environment.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of LGUG2Z/komorebi@e0709f02bf (2026-09-06). Data as JSON: /api/errors/e8bfd528a2ca9e5d. Report an issue: GitHub.