{"record":{"id":"85f59324c8112c8b","repo":"atuinsh/atuin","slug":"could-not-determine-home-directory","errorCode":null,"errorMessage":"could not determine home directory","messagePattern":"could not determine home directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin-common/src/utils.rs","lineNumber":112,"sourceCode":"        // if .git is a file (worktree), resolve to the main repo root\n        if let Some(main_repo) = resolve_git_worktree(&gitdir) {\n            return Some(main_repo);\n        }\n        return Some(gitdir);\n    }\n\n    None\n}\n\n// TODO: more reliable, more tested\n// I don't want to use ProjectDirs, it puts config in awkward places on\n// mac. Data too. Seems to be more intended for GUI apps.\n\n#[must_use]\npub fn home_dir() -> PathBuf {\n    directories::BaseDirs::new()\n        .map(|d| d.home_dir().to_path_buf())\n        .expect(\"could not determine home directory\")\n}\n\n/// Read an environment variable that must be nonempty.\n///\n/// This function will never return an empty string: if the environment variable is set but empty,\n/// [`None`] is returned.\n#[must_use]\npub fn env_nonempty(name: &str) -> Option<OsString> {\n    std::env::var_os(name).filter(|value| !value.is_empty())\n}\n\n/// Read an environment variable that must be an absolute path.\n///\n/// This is usually done in the name of XDG-compliance which requires that paths given through\n/// environment variables are absolute.\npub fn env_abspath(name: &str) -> Option<PathBuf> {\n    env_nonempty(name).map(PathBuf::from).filter(|s| s.is_absolute())\n}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/atuinsh/atuin/blob/c0c717ab04c881764bcad4b3d169a507e2432643/crates/atuin-common/src/utils.rs#L94-L130","documentation":"`home_dir()` resolves the user's home directory via the `directories` crate (`BaseDirs::new()`), which reads $HOME (or platform equivalents like getpwuid). It panics when no home directory can be determined at all. Nearly all Atuin config/data paths depend on this.","triggerScenarios":"Calling `home_dir()` (directly or via `config_dir`, `data_dir`, `logs_dir`, `xdg_config_home`, `path`) when $HOME is unset and the passwd database has no entry for the current UID.","commonSituations":"Running atuin under systemd/supervisors with a sanitized environment missing $HOME; cron jobs without HOME set; `sudo -u otheruser` with env_reset; Docker containers running as a non-root UID absent from /etc/passwd.","solutions":["Set the HOME environment variable (e.g. `export HOME=/home/user`) before running atuin","If using sudo, run `sudo -E` or configure sudo to preserve HOME","In containers, ensure the user exists in /etc/passwd (`useradd`) or set HOME explicitly","For systemd units, add `Environment=HOME=%h` or use a User= with a valid passwd entry"],"exampleFix":"// before\natuin sync   # fails: could not determine home directory\n// after\nexport HOME=\"$(getent passwd \"$(id -u)\" | cut -d: -f6)\"\natuin sync","handlingStrategy":"validation","validationCode":"// Pre-flight check before running atuin:\nif std::env::var_os(\"HOME\").map_or(true, |h| h.is_empty()) {\n    eprintln!(\"HOME is not set; set it before running atuin\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set HOME in systemd units, cron entries, and Dockerfiles","Use `sudo -E` or `env_keep=HOME` when sudoing","Create passwd entries for non-root container UIDs","Smoke-test CLI tools with a sanitized env before deploying them in supervisors"],"tags":["environment","home-directory","panic","config"],"backgroundTag":"missing-env-var","analyzedSha":"c0c717ab04c881764bcad4b3d169a507e2432643","analyzedAt":"2026-09-12T07:40:01.341Z","contentChangedAt":"2026-09-12T07:40:01.341Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}