{"record":{"id":"332f92a452044651","repo":"Schniz/fnm","slug":"can-t-get-home-directory","errorCode":null,"errorMessage":"Can't get home directory","messagePattern":"Can't get home directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/directories.rs","lineNumber":61,"sourceCode":"    pub fn strategy(&self) -> &impl BaseStrategy {\n        &self.0\n    }\n\n    pub fn default_base_dir(&self) -> PathBuf {\n        let strategy = self.strategy();\n        let modern = strategy.data_dir().join(\"fnm\");\n        if modern.exists() {\n            return modern;\n        }\n\n        let legacy = strategy.home_dir().join(\".fnm\");\n        if legacy.exists() {\n            return legacy;\n        }\n\n        #[cfg(target_os = \"macos\")]\n        {\n            let basedirs = etcetera::base_strategy::Apple::new().expect(\"Can't get home directory\");\n            let legacy = basedirs.data_dir().join(\"fnm\");\n            if legacy.exists() {\n                return legacy;\n            }\n        }\n\n        modern.ensure_exists_silently()\n    }\n\n    pub fn multishell_storage(&self) -> PathBuf {\n        let basedirs = self.strategy();\n        let dir = runtime_dir(basedirs)\n            .or_else(|| state_dir(basedirs))\n            .unwrap_or_else(|| cache_dir(basedirs));\n        dir.join(\"fnm_multishells\")\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Schniz/fnm/blob/86adc9676ceb2a509b21e75e74048b93c89f097d/src/directories.rs#L43-L79","documentation":"On macOS only, when neither the modern data dir (`~/Library/Application Support/fnm`) nor the legacy `~/.fnm` exists yet, `Directories::default_base_dir` constructs an etcetera `Apple` base strategy — which resolves the home directory — and unwraps it with `.expect(\"Can't get home directory\")`. If the home directory cannot be determined at that moment, fnm panics while computing where to put its files.","triggerScenarios":"First run of any fnm command on macOS (no ~/.fnm, no Application Support/fnm) in an environment where HOME is unset or unresolvable — `env -i fnm list`, launchd agents with a stripped environment, or ssh contexts with unusual passwd entries.","commonSituations":"macOS LaunchAgents/LaunchDaemons that omit HOME; CI runners on macOS with minimal env; scripts run via `env -i`; first-ever invocation right after install in a sanitized shell.","solutions":["Ensure HOME is set and writable: `export HOME=\"$HOME\"` sanity check, or set it explicitly in the launching plist/agent (`EnvironmentVariables` → HOME).","Pre-create either `~/.fnm` or `~/Library/Application Support/fnm` so the earlier existence checks return before the Apple fallback runs.","For daemons/agents, run fnm once from a normal login shell first to materialize the directories.","Update fnm — this fallback should degrade to a user-facing error rather than a panic."],"exampleFix":"# before\nenv -i fnm list   # macOS first run, panic: Can't get home directory\n\n# after\nmkdir -p \"$HOME/Library/Application Support/fnm\"\nenv -i HOME=\"$HOME\" fnm list   # ok","handlingStrategy":"validation","validationCode":"# macOS: ensure fnm dirs exist before first run in stripped environments\nmkdir -p \"$HOME/Library/Application Support/fnm\" || exit 1\n[ -n \"$HOME\" ] || { echo 'HOME unset; aborting' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| run_fnm(args))\n    .unwrap_or_else(|_| {\n        eprintln!(\"fnm could not resolve the home directory; set HOME and retry\");\n        std::process::exit(1);\n    });","preventionTips":["Set EnvironmentVariables.HOME in launchd plists that invoke fnm.","Run fnm once from a login shell so the data dirs are created before daemon contexts use it.","Keep ~/.fnm or Application Support/fnm present after initial setup."],"tags":["rust","macos","home-directory","environment-variable","panic","etcetera"],"backgroundTag":"home-directory-not-found","analyzedSha":"86adc9676ceb2a509b21e75e74048b93c89f097d","analyzedAt":"2026-08-16T21:43:05.725Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}