{"record":{"id":"1eb59e517d083bb0","repo":"Hmbown/CodeWhale","slug":"home-directory-unavailable","errorCode":null,"errorMessage":"Home directory unavailable","messagePattern":"Home directory unavailable","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp/external_import.rs","lineNumber":509,"sourceCode":"pub struct ImportContext<'a> {\n    pub workspace: &'a Path,\n    pub mcp_path: &'a Path,\n    pub plugins: &'a crate::plugins::PluginRegistry,\n    pub home: PathBuf,\n    pub codewhale_home: PathBuf,\n}\nimpl<'a> ImportContext<'a> {\n    pub fn new(\n        workspace: &'a Path,\n        mcp_path: &'a Path,\n        plugins: &'a crate::plugins::PluginRegistry,\n    ) -> anyhow::Result<Self> {\n        Ok(Self {\n            workspace,\n            mcp_path,\n            plugins,\n            home: crate::config::effective_home_dir()\n                .ok_or_else(|| anyhow::anyhow!(\"Home directory unavailable\"))?,\n            codewhale_home: codewhale_config::codewhale_home()?,\n        })\n    }\n    fn discover(&self) -> (Vec<ImportCandidate>, Vec<ImportProblem>) {\n        let sources = [\n            (\n                self.home.join(\".claude.json\"),\n                ExternalMcpSourceKind::ClaudeJson,\n            ),\n            (\n                self.workspace.join(\".mcp.json\"),\n                ExternalMcpSourceKind::ProjectMcpJson,\n            ),\n            (\n                self.codewhale_home.join(\"mcp-marketplace.json\"),\n                ExternalMcpSourceKind::Marketplace,\n            ),\n        ];","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp/external_import.rs#L491-L527","documentation":"Thrown when constructing the MCP external-import collector: `crate::config::effective_home_dir()` returned None, so no home directory could be resolved. The import feature needs the home dir to discover external MCP client configs (e.g. other tools' config files), and without it discovery cannot run.","triggerScenarios":"Calling `ImportContext::new` (or the constructor wrapping `Self { ... }`) on a system where $HOME is unset and no passwd-derived home could be determined — e.g. a stripped CI container, an systemd/timer service with a minimal environment, or running the binary via a login shell replacement that clears the environment.","commonSituations":"Docker containers running as a non-root user without HOME set; cron/systemd units lacking `Environment=HOME=...`; SSH exec commands without `-l` that skip loading the environment.","solutions":["Set the HOME environment variable before launching codewhale (e.g. `Environment=HOME=/home/user` in a systemd unit or `export HOME=$(getent passwd $USER | cut -d: -f6)`).","Run under a login shell (`su -l user -c ...` or `ssh user@host`) so HOME is populated.","If running in a container, add `ENV HOME=/root` or run with `docker run -e HOME=...`."],"exampleFix":"// before (Dockerfile)\nCMD [\"codewhale\"]\n// after\nENV HOME=/home/appuser\nCMD [\"codewhale\"]","handlingStrategy":"fallback","validationCode":"let has_home = std::env::var_os(\"HOME\").map(|h| !h.is_empty()).unwrap_or(false);\nif !has_home { eprintln!(\"HOME must be set before running codewhale\"); }","typeGuard":"fn has_home_dir() -> bool { crate::config::effective_home_dir().is_some() }","tryCatchPattern":"match ImportContext::new(...) {\n    Err(e) if e.to_string().contains(\"Home directory unavailable\") => {\n        // fall back to an explicit home or surface a setup hint\n    }\n    other => other?,\n}","preventionTips":["Always launch the binary with HOME set in service/container definitions","Add HOME to smoke-test environments","Prefer login shells for remote execution"],"tags":["config","environment","home-directory"],"backgroundTag":"missing-env-var","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}