{"record":{"id":"deff5a276161bd06","repo":"spacedriveapp/spacedrive","slug":"could-not-determine-home-directory-deff5a","errorCode":null,"errorMessage":"Could not determine home directory","messagePattern":"Could not determine home directory","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"core/src/config/mod.rs","lineNumber":22,"sourceCode":"use chrono::{DateTime, Utc};\nuse serde::{Deserialize, Serialize};\nuse std::fs;\nuse std::path::PathBuf;\n\npub mod app_config;\npub mod migration;\n\npub use app_config::{\n\tAppConfig, JobLoggingConfig, LogStreamConfig, LoggingConfig, ProxyPairingConfig, ServiceConfig,\n\tSpacebotConfig,\n};\npub use migration::Migrate;\n\n/// Default data directory: `~/.spacedrive` on desktop, platform data dir on mobile.\npub fn default_data_dir() -> Result<PathBuf> {\n\t#[cfg(not(any(target_os = \"ios\", target_os = \"android\")))]\n\tlet dir = dirs::home_dir()\n\t\t.ok_or_else(|| anyhow!(\"Could not determine home directory\"))?\n\t\t.join(\".spacedrive\");\n\n\t#[cfg(target_os = \"ios\")]\n\tlet dir = dirs::data_dir()\n\t\t.ok_or_else(|| anyhow!(\"Could not determine data directory\"))?\n\t\t.join(\"spacedrive\");\n\n\t#[cfg(target_os = \"android\")]\n\tlet dir = dirs::data_dir()\n\t\t.ok_or_else(|| anyhow!(\"Could not determine data directory\"))?\n\t\t.join(\"spacedrive\");\n\n\t// Create directory if it doesn't exist\n\tfs::create_dir_all(&dir)?;\n\n\tOk(dir)\n}\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/config/mod.rs#L4-L40","documentation":"Thrown by default_data_dir() on desktop platforms (not iOS/Android) when dirs::home_dir() returns None. The function then cannot build the default '~/.spacedrive' data directory, and every config load, daemon startup, or model/speech/indexing op that calls default_data_dir()? fails with this error. dirs::home_dir() returns None when the HOME environment variable is unset or empty on Linux/macOS, or USERPROFILE is missing on Windows.","triggerScenarios":"Running sd-daemon or sd-cli without a --data-dir override while HOME is unset or empty: systemd/cron/launchd services with a scrubbed environment, `env -i cargo run`, minimal Docker containers that lack the HOME env var, or CI runners.","commonSituations":"A systemd unit without `Environment=\"HOME=...\"`; a Dockerfile that switches USER without setting HOME; CI jobs; processes spawned from daemons that clear the environment; running as a user whose passwd entry is broken.","solutions":["Run the daemon with an explicit directory: `cargo run --bin sd-daemon -- --data-dir /var/lib/spacedrive` (see Args in core/src/bin/daemon.rs:27).","If HOME is expected to exist, set it: `export HOME=/home/user` (Linux/macOS) or ensure USERPROFILE is set on Windows, then restart the daemon.","For systemd services add `Environment=\"HOME=/var/lib/spacedrive\"` (or WorkingDirectory plus EnvironmentFile) to the unit file.","For containers, add `ENV HOME=/root` or `USER` with a proper home directory in the image."],"exampleFix":"# before (fails: HOME unset)\nsystemctl start sd-daemon\n\n# after (unit file)\n[Service]\nEnvironment=\"HOME=/var/lib/spacedrive\"\nExecStart=/usr/bin/sd-daemon\n\n# or bypass the default entirely\nsd-daemon --data-dir /var/lib/spacedrive","handlingStrategy":"validation","validationCode":"// Rust: verify a home directory is resolvable before starting the daemon\nfn ensure_home_available() -> anyhow::Result<()> {\n    #[cfg(not(any(target_os = \"ios\", target_os = \"android\")))]\n    if dirs::home_dir().is_none() {\n        anyhow::bail!(\"HOME is not set; run with --data-dir or export HOME\");\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"// treat as fatal startup misconfiguration; report the missing env, do not invent a fallback dir\nmatch sd_core::config::default_data_dir() {\n    Ok(dir) => { /* proceed */ },\n    Err(e) if e.to_string().contains(\"home directory\") => {\n        eprintln!(\"set $HOME or pass --data-dir\");\n        std::process::exit(1);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always pass --data-dir when running sd-daemon as a service or in containers.","Include `Environment=\"HOME=...\"` in systemd units; set ENV HOME in Dockerfiles.","Never run the daemon with `env -i` or a scrubbed environment."],"tags":["config","environment","startup","filesystem"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}