{"record":{"id":"eb4669b14f2f1e9f","repo":"spacedriveapp/spacedrive","slug":"could-not-determine-data-directory","errorCode":null,"errorMessage":"Could not determine data directory","messagePattern":"Could not determine data directory","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"core/src/config/mod.rs","lineNumber":27,"sourceCode":"pub 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\n/// User preferences\n#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct Preferences {\n\tpub theme: String,    // \"light\", \"dark\", \"system\"\n\tpub language: String, // ISO 639-1 code","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/config/mod.rs#L9-L45","documentation":"Thrown by default_data_dir() in the #[cfg(target_os = \"ios\")] branch when dirs::data_dir() returns None. On iOS this resolves the platform data directory (app container/Library/Application Support) and joins 'spacedrive'. It fails when the iOS platform APIs cannot report the container path, typically because the process is not running inside a proper app sandbox (no bundle identifier / NSHomeDirectory unavailable).","triggerScenarios":"Executing iOS-targeted core code outside a real app lifecycle: plain unit tests run on the iOS simulator host, an iOS binary launched via ssh/debug shell without a bundle container, or a test harness compiled with target_os=ios that calls default_data_dir().","commonSituations":"CI running `cargo test` for an iOS target without xctest-booted app containers; prototype iOS app (apps/ios) launched in an unsupported way; entitlement or provisioning changes that break the app container.","solutions":["Run the code inside the actual app process (Xcode/xcitest), where NSHomeDirectory and the data container are available.","Pass an explicit data directory through AppConfig instead of relying on default_data_dir() in test builds.","In Rust tests, skip or gate assertions that call default_data_dir() on iOS with #[cfg(not(target_os = \"ios\"))]."],"exampleFix":"// before\nlet dir = sd_core::config::default_data_dir()?; // fails outside app container\n\n// after (tests / tools)\n#[cfg(target_os = \"ios\")]\nlet dir = std::path::PathBuf::from(\"/tmp/spacedrive-test\");\n#[cfg(not(target_os = \"ios\"))]\nlet dir = sd_core::config::default_data_dir()?;","handlingStrategy":"validation","validationCode":"// iOS: only rely on default_data_dir() inside a real app container\n#[cfg(target_os = \"ios\")]\nfn data_dir() -> anyhow::Result<std::path::PathBuf> {\n    dirs::data_dir()\n        .map(|d| d.join(\"spacedrive\"))\n        .ok_or_else(|| anyhow::anyhow!(\"no iOS container; run inside the app or inject a data dir\"))\n}","typeGuard":null,"tryCatchPattern":"// in tests/tools, fail fast with a clear message instead of crashing deep in config load\nlet dir = match sd_core::config::default_data_dir() {\n    Ok(d) => d,\n    Err(_) if cfg!(test) => std::path::PathBuf::from(\"/tmp/spacedrive-test\"),\n    Err(e) => return Err(e),\n};","preventionTips":["Run iOS-targeted core logic through XCTest inside the app bundle.","Inject the data directory explicitly in test harnesses.","Gate config tests that assume a container with #[cfg(not(target_os = \"ios\"))]."],"tags":["config","ios","environment","startup"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}