spacedriveapp/spacedrive · error · LibraryError

Failed to create libraries directory: {}

Error message

Failed to create libraries directory: {}

What it means

create_library_with_id failed to create the base directory for libraries with tokio::fs::create_dir_all. The base path is the first configured search path, falling back to ~/Spacedrive/Libraries. The message wraps the OS error, but the original io::ErrorKind is discarded in favor of ErrorKind::Other, so parse the formatted text for the real cause.

Source

Thrown at core/src/library/manager.rs:186

			return Err(LibraryError::InvalidName(
				"Name cannot be empty".to_string(),
			));
		}

		// Sanitize name for filesystem
		let safe_name = sanitize_filename(&name);

		// Use default library location
		let base_path = self.search_paths.first().cloned().unwrap_or_else(|| {
			dirs::home_dir()
				.unwrap_or_else(|| PathBuf::from("."))
				.join("Spacedrive")
				.join("Libraries")
		});

		// Ensure base path exists
		tokio::fs::create_dir_all(&base_path).await.map_err(|e| {
			LibraryError::IoError(std::io::Error::new(
				std::io::ErrorKind::Other,
				format!("Failed to create libraries directory: {}", e),
			))
		})?;

		// Find unique library path
		let library_path = find_unique_library_path(&base_path, &safe_name).await?;

		// Create library directory
		tokio::fs::create_dir_all(&library_path).await?;

		// Initialize library with provided UUID (instead of generating new one)
		self.initialize_library_with_id(
			&library_path,
			library_id,
			name,
			description,
			context.clone(),

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Verify the daemon user can create the base path (fix ownership or mode on the parent directory)
  2. Check that the first configured search path exists, is mounted, and is writable, or configure a valid one
  3. Free disk space or raise the quota
  4. Preserve the original error kind when wrapping so PermissionDenied is distinguishable from other IO failures

Example fix

// before
LibraryError::IoError(std::io::Error::new(std::io::ErrorKind::Other, format!("Failed to create libraries directory: {}", e)))

// after
LibraryError::IoError(std::io::Error::new(e.kind(), format!("Failed to create libraries directory: {}", e)))
Defensive patterns

Strategy: validation

Validate before calling

// Verify the base location is creatable and writable before creating a library
let base = search_paths.first().cloned().unwrap_or_else(|| dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join("Spacedrive").join("Libraries"));
tokio::fs::create_dir_all(&base).await?;
let probe = base.join(".write-test");
tokio::fs::write(&probe, b"x").await?;
tokio::fs::remove_file(&probe).await?;

Try / catch

match manager.create_library_with_id(id, name, desc, ctx).await {
    Err(LibraryError::IoError(e)) if e.to_string().contains("Failed to create libraries directory") => {
        // surface a targeted message: check permissions, mount status, and disk space
    }
    other => other,
}

Prevention

When it happens

Trigger: The daemon user lacks write permission on the base path or its parent; the configured search path points to an unmounted or read-only volume; disk full or quota exceeded; dirs::home_dir() failed and the '.' fallback is not writable.

Common situations: Running as a service user without a real home directory; containers and sandboxes with restrictive mounts; NFS or removable media as the library location.

Related errors


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