{"record":{"id":"79d1c4832e8a1b6b","repo":"spacedriveapp/spacedrive","slug":"could-not-determine-home-directory-79d1c4","errorCode":null,"errorMessage":"Could not determine home directory","messagePattern":"Could not determine home directory","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/tauri/sd-tauri-core/src/lib.rs","lineNumber":47,"sourceCode":"\tpub code: i32,\n\tpub message: String,\n\t#[serde(skip_serializing_if = \"Option::is_none\")]\n\tpub data: Option<serde_json::Value>,\n}\n\n// Core state management will be added here once we understand\n// the core's initialization patterns better\n// For now this is a skeleton that provides the types\n\npub mod commands {\n\t// Tauri command implementations will go here\n\t// Following the pattern from sd-ios-core but for Tauri's IPC\n}\n\n/// Default data directory: `~/.spacedrive`\npub fn default_data_dir() -> anyhow::Result<std::path::PathBuf> {\n\tlet dir = dirs::home_dir()\n\t\t.ok_or_else(|| anyhow::anyhow!(\"Could not determine home directory\"))?\n\t\t.join(\".spacedrive\");\n\n\t// Create directory if it doesn't exist\n\tstd::fs::create_dir_all(&dir)?;\n\n\tOk(dir)\n}\n","sourceCodeStart":29,"sourceCodeEnd":55,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/tauri/sd-tauri-core/src/lib.rs#L29-L55","documentation":"sd-tauri-core's default_data_dir() builds ~/.spacedrive from dirs::home_dir(); when that returns None (no HOME/USERPROFILE resolvable), the anyhow! fires before any directory is created. Home lookup depends entirely on the process environment, so headless or stripped environments trigger it.","triggerScenarios":"Running the Tauri core code under systemd/cron without HOME set; minimal containers; setuid or otherwise sanitized contexts.","commonSituations":"Packaging the desktop core into a service; tests executed in bare CI containers; Windows sessions missing USERPROFILE.","solutions":["Set HOME explicitly in the service unit or container (e.g. Environment=HOME=/var/lib/spacedrive)","Invoke with an explicit data directory instead of relying on default_data_dir()","On Windows, ensure USERPROFILE is present in the environment"],"exampleFix":"# systemd unit\n[Service]\nEnvironment=HOME=/var/lib/spacedrive\n\n# or in code, avoid the default entirely\nlet dir = std::path::PathBuf::from(\"/var/lib/spacedrive\");","handlingStrategy":"fallback","validationCode":"fn ensure_home() -> Option<std::path::PathBuf> {\n    std::env::var_os(\"HOME\")\n        .or_else(|| std::env::var_os(\"USERPROFILE\"))\n        .map(std::path::PathBuf::from)\n}","typeGuard":null,"tryCatchPattern":"let dir = match dirs::home_dir() {\n    Some(h) => h.join(\".spacedrive\"),\n    None => std::path::PathBuf::from(\"/var/lib/spacedrive\"), // explicit fallback for service contexts\n};","preventionTips":["Set HOME explicitly in systemd units, cron jobs, and container images that run the core","Let callers pass an explicit data dir so startup never depends on environment detection","Fail with a message naming the missing variable (HOME/USERPROFILE) to speed diagnosis"],"tags":["environment","filesystem","tauri","config"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}