spacedriveapp/spacedrive · error · anyhow::Error

No library selected. Run 'sd library list' to see available

Error message

No library selected. Run 'sd library list' to see available libraries

What it means

Thrown by 'sd spaces list' when ctx.library_id is None. The CLI Context loads library_id from cli_config.current_library_id at startup (apps/cli/src/context.rs:32), so this means no current library is recorded in the CLI config - typically because no library has been created or switched to yet. Spaces are a library-scoped query, so a library ID is mandatory.

Source

Thrown at apps/cli/src/domains/spaces/mod.rs:28

	List,
	/// Get space layout
	Layout {
		/// Space ID
		space_id: String,
	},
}

pub async fn exec(cmd: SpacesCmd, ctx: &Context) -> Result<()> {
	match cmd {
		SpacesCmd::List => list_spaces(ctx).await,
		SpacesCmd::Layout { space_id } => get_layout(ctx, space_id).await,
	}
}

async fn list_spaces(ctx: &Context) -> Result<()> {
	// Get current library ID
	let library_id = ctx.library_id.ok_or_else(|| {
		anyhow::anyhow!("No library selected. Run 'sd library list' to see available libraries")
	})?;

	println!("Library ID: {}", library_id);

	// Create query input
	let input = SpacesListQueryInput;

	// Execute query through the client
	let response = ctx.core.query(&input, Some(library_id)).await?;

	println!(
		"\nRaw response: {}",
		serde_json::to_string_pretty(&response)?
	);

	let result: sd_core::ops::spaces::SpacesListOutput = serde_json::from_value(response)
		.map_err(|e| anyhow::anyhow!("Failed to parse response: {}", e))?;

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Run 'sd library list' to see existing libraries
  2. Create one with 'sd library create' if none exists, or switch with 'sd library switch'
  3. Re-run 'sd spaces list' once a current library is set
Defensive patterns

Strategy: validation

Validate before calling

match ctx.get_current_library_id() {
    Some(id) => id,
    None => {
        eprintln!("No current library. Run 'sd library list' then 'sd library switch <id>'.");
        return Ok(());
    }
}

Type guard

fn has_current_library(ctx: &Context) -> bool {
    ctx.library_id.is_some()
}

Prevention

When it happens

Trigger: Running 'sd spaces list' on a fresh install before 'sd library create'; after the stored current library was deleted or the config file was reset.

Common situations: New machine or fresh data dir; the config's current_library_id was cleared; the daemon was reinitialized and the old library ID no longer resolves.

Related errors


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