spacedriveapp/spacedrive · critical · anyhow::Error
Could not determine data directory
Error message
Could not determine data directory
What it means
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).
Source
Thrown at core/src/config/mod.rs:27
pub mod app_config;
pub mod migration;
pub use app_config::{
AppConfig, JobLoggingConfig, LogStreamConfig, LoggingConfig, ProxyPairingConfig, ServiceConfig,
SpacebotConfig,
};
pub use migration::Migrate;
/// Default data directory: `~/.spacedrive` on desktop, platform data dir on mobile.
pub fn default_data_dir() -> Result<PathBuf> {
#[cfg(not(any(target_os = "ios", target_os = "android")))]
let dir = dirs::home_dir()
.ok_or_else(|| anyhow!("Could not determine home directory"))?
.join(".spacedrive");
#[cfg(target_os = "ios")]
let dir = dirs::data_dir()
.ok_or_else(|| anyhow!("Could not determine data directory"))?
.join("spacedrive");
#[cfg(target_os = "android")]
let dir = dirs::data_dir()
.ok_or_else(|| anyhow!("Could not determine data directory"))?
.join("spacedrive");
// Create directory if it doesn't exist
fs::create_dir_all(&dir)?;
Ok(dir)
}
/// User preferences
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Preferences {
pub theme: String, // "light", "dark", "system"
pub language: String, // ISO 639-1 codeView on GitHub (pinned to 6dfeccf211)
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"))].
Example fix
// before
let dir = sd_core::config::default_data_dir()?; // fails outside app container
// after (tests / tools)
#[cfg(target_os = "ios")]
let dir = std::path::PathBuf::from("/tmp/spacedrive-test");
#[cfg(not(target_os = "ios"))]
let dir = sd_core::config::default_data_dir()?; Defensive patterns
Strategy: validation
Validate before calling
// iOS: only rely on default_data_dir() inside a real app container
#[cfg(target_os = "ios")]
fn data_dir() -> anyhow::Result<std::path::PathBuf> {
dirs::data_dir()
.map(|d| d.join("spacedrive"))
.ok_or_else(|| anyhow::anyhow!("no iOS container; run inside the app or inject a data dir"))
} Try / catch
// in tests/tools, fail fast with a clear message instead of crashing deep in config load
let dir = match sd_core::config::default_data_dir() {
Ok(d) => d,
Err(_) if cfg!(test) => std::path::PathBuf::from("/tmp/spacedrive-test"),
Err(e) => return Err(e),
}; Prevention
- 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"))].
When it happens
Trigger: 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().
Common situations: 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.
Related errors
- Could not determine home directory
- Could not determine home directory
- Cannot set key: {}
- Failed to start systemd service: {}
- No library selected. Run 'sd library list' to see available
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/eb4669b14f2f1e9f.
Report an issue: GitHub.