spacedriveapp/spacedrive · error · anyhow::Error

Could not determine home directory

Error message

Could not determine home directory

What it means

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.

Source

Thrown at apps/tauri/sd-tauri-core/src/lib.rs:47

	pub code: i32,
	pub message: String,
	#[serde(skip_serializing_if = "Option::is_none")]
	pub data: Option<serde_json::Value>,
}

// Core state management will be added here once we understand
// the core's initialization patterns better
// For now this is a skeleton that provides the types

pub mod commands {
	// Tauri command implementations will go here
	// Following the pattern from sd-ios-core but for Tauri's IPC
}

/// Default data directory: `~/.spacedrive`
pub fn default_data_dir() -> anyhow::Result<std::path::PathBuf> {
	let dir = dirs::home_dir()
		.ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?
		.join(".spacedrive");

	// Create directory if it doesn't exist
	std::fs::create_dir_all(&dir)?;

	Ok(dir)
}

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Set HOME explicitly in the service unit or container (e.g. Environment=HOME=/var/lib/spacedrive)
  2. Invoke with an explicit data directory instead of relying on default_data_dir()
  3. On Windows, ensure USERPROFILE is present in the environment

Example fix

# systemd unit
[Service]
Environment=HOME=/var/lib/spacedrive

# or in code, avoid the default entirely
let dir = std::path::PathBuf::from("/var/lib/spacedrive");
Defensive patterns

Strategy: fallback

Validate before calling

fn ensure_home() -> Option<std::path::PathBuf> {
    std::env::var_os("HOME")
        .or_else(|| std::env::var_os("USERPROFILE"))
        .map(std::path::PathBuf::from)
}

Try / catch

let dir = match dirs::home_dir() {
    Some(h) => h.join(".spacedrive"),
    None => std::path::PathBuf::from("/var/lib/spacedrive"), // explicit fallback for service contexts
};

Prevention

When it happens

Trigger: Running the Tauri core code under systemd/cron without HOME set; minimal containers; setuid or otherwise sanitized contexts.

Common situations: Packaging the desktop core into a service; tests executed in bare CI containers; Windows sessions missing USERPROFILE.

Related errors


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/79d1c4832e8a1b6b. Report an issue: GitHub.