{"record":{"id":"b9ea7216cae2c64d","repo":"Hmbown/CodeWhale","slug":"could-not-resolve-home-directory-for-filekeyringst","errorCode":null,"errorMessage":"could not resolve home directory for FileKeyringStore","messagePattern":"could not resolve home directory for FileKeyringStore","errorType":"exception","errorClass":"SecretsError","httpStatus":null,"severity":"error","filePath":"crates/secrets/src/lib.rs","lineNumber":677,"sourceCode":"fn default_codewhale_secrets_path() -> Result<PathBuf, SecretsError> {\n    Ok(codewhale_paths::codewhale_home()\n        .map_err(|error| {\n            SecretsError::Io(std::io::Error::new(std::io::ErrorKind::InvalidInput, error))\n        })?\n        .ok_or_else(home_resolution_error)?\n        .join(\"secrets\")\n        .join(\"secrets.json\"))\n}\n\nfn legacy_deepseek_secrets_path() -> Result<PathBuf, SecretsError> {\n    Ok(codewhale_paths::legacy_deepseek_home()\n        .ok_or_else(home_resolution_error)?\n        .join(\"secrets\")\n        .join(\"secrets.json\"))\n}\n\nfn home_resolution_error() -> SecretsError {\n    SecretsError::Io(std::io::Error::new(\n        std::io::ErrorKind::NotFound,\n        \"could not resolve home directory for FileKeyringStore\",\n    ))\n}\n\n#[derive(Debug, Clone, Copy, PartialEq, Eq)]\nenum SecretBackendSelection {\n    File,\n    System,\n    Unknown,\n}\n\n/// Secret-store backend selected by configuration for a structural diagnostic.\n///\n/// This type deliberately describes only configuration and filesystem shape.\n/// It never implies that a provider credential exists.\n#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]\n#[serde(rename_all = \"snake_case\")]","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/secrets/src/lib.rs#L659-L695","documentation":"FileKeyringStore persists API keys in <home>/.codewhale/secrets/secrets.json (or legacy <home>/.deepseek/secrets/secrets.json). Both paths are derived from codewhale_paths::user_home(), which tries HOME, then USERPROFILE, then Windows HOMEDRIVE+HOMEPATH, then the platform dirs::home_dir() resolver. When every source is missing or empty, default_codewhale_secrets_path()/legacy_deepseek_secrets_path() fail with this NotFound io::Error wrapped in SecretsError::Io, so any get/set/delete on the file backend (e.g. storing a provider key) fails before any file I/O happens.","triggerScenarios":"Constructing or calling FileKeyringStore (get/set/delete of a secret) in a process whose environment has no usable HOME and no USERPROFILE and whose platform home resolver returns None: docker run without -e HOME, a systemd unit or cron job without Environment=\"HOME=...\", a CI step that scrubs env vars, or HOME exported as an empty/whitespace string (treated as unset by normalize_path_value).","commonSituations":"Headless containers and CI runners that never set HOME; launching codewhale from a service manager, launcher, or GUI wrapper that strips the environment; Windows processes where USERPROFILE is unset; hermetic test harnesses that remove env vars.","solutions":["Set HOME to an absolute writable path in the launching environment (export HOME=/root, or -e HOME=/root for docker) and rerun; empty values count as unset","For systemd/cron, add Environment=\"HOME=/var/lib/codewhale\" (and a User=) to the unit/job definition","Set CODEWHALE_HOME=/absolute/path to pin the Codewhale home independently of the user-home resolver","On Windows ensure USERPROFILE (or HOMEDRIVE+HOMEPATH) is present in the environment that spawns the process"],"exampleFix":"# before (container/CI: no HOME set)\ndocker run --rm codewhale codewhale login   # -> could not resolve home directory for FileKeyringStore\n\n# after\ndocker run --rm -e HOME=/root codewhale codewhale login","handlingStrategy":"validation","validationCode":"fn home_resolvable() -> Option<PathBuf> {\n    codewhale_paths::user_home()\n}\n\n// before touching the secrets store:\nlet home = home_resolvable().or_else(|| {\n    eprintln!(\"HOME/USERPROFILE not set; set HOME or CODEWHALE_HOME before storing secrets\");\n    None\n})?;","typeGuard":null,"tryCatchPattern":"match result {\n    Err(SecretsError::Io(ref e)) if e.kind() == io::ErrorKind::NotFound\n        && e.to_string().contains(\"home directory\") =>\n    {\n        eprintln!(\"No home directory: export HOME=/path (or CODEWHALE_HOME=...) and retry\");\n    }\n    other => other?,\n}","preventionTips":["Set HOME (or CODEWHALE_HOME) explicitly in containers, systemd units, and CI before any secrets operation","Treat empty/whitespace HOME as unset — the resolver does","In integration tests, pin the environment instead of scrubbing it blind"],"tags":["secrets","home-directory","environment","configuration"],"backgroundTag":"missing-home-directory-env","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}