spacedriveapp/spacedrive · error · anyhow::Error

Path must be a directory: {}

Error message

Path must be a directory: {}

What it means

Thrown by the interactive location-add flow when the entered path exists (PathBuf::exists() is true) but PathBuf::is_dir() is false, i.e. the user pointed the location at a regular file. Locations index directory trees, so a file path is rejected.

Source

Thrown at apps/cli/src/domains/location/mod.rs:158

	println!("\n=== Add New Location ===\n");

	// 1. Location type
	let location_type = select(
		"What type of location would you like to add?",
		&["Local filesystem".to_string(), "Cloud storage".to_string()],
	)?;

	let sd_path = if location_type == 0 {
		// Local filesystem
		let path_str = text("Enter the local path", false)?.unwrap();
		let path_buf = std::path::PathBuf::from(path_str);

		// Validate that path exists
		if !path_buf.exists() {
			anyhow::bail!("Path does not exist: {}", path_buf.display());
		}
		if !path_buf.is_dir() {
			anyhow::bail!("Path must be a directory: {}", path_buf.display());
		}

		SdPath::local(path_buf)
	} else {
		// Cloud storage
		use sd_core::ops::volumes::list::VolumeListQueryInput;

		let volumes: sd_core::ops::volumes::list::VolumeListOutput = execute_query!(
			ctx,
			VolumeListQueryInput {
				filter: sd_core::ops::volumes::VolumeFilter::TrackedOnly
			}
		);

		if volumes.volumes.is_empty() {
			anyhow::bail!(
				"No cloud volumes found. Add a cloud volume first with:\n  sd volume add-cloud"
			);

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Point the location at the directory containing the file, e.g. /home/user instead of /home/user/movie.mp4
  2. Check for a trailing filename or accidental paste in the prompt
  3. If the path is a symlink, make sure it resolves to a directory
Defensive patterns

Strategy: validation

Validate before calling

let meta = std::fs::metadata(&path_buf)?;
if !meta.is_dir() {
    eprintln!("'{}' is a file; locations must be directories", path_buf.display());
    return Ok(());
}

Type guard

fn is_directory(p: &std::path::Path) -> bool {
    p.is_dir()
}

Prevention

When it happens

Trigger: Entering a file path such as /home/user/movie.mp4 (or a symlink that resolves to a file) in the local path prompt.

Common situations: User wants to track a single file and doesn't realize locations are directory-scoped; autocomplete in the terminal completes to a filename; special files like /dev/null or FIFOs also fail is_dir().

Related errors


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