spacedriveapp/spacedrive · error · anyhow::Error

No library selected

Error message

No library selected

What it means

Thrown by 'sd spaces layout <space_id>' when ctx.library_id is None - identical root cause to the spaces list error, with a terser message. The layout query (SpaceLayoutQueryInput) is library-scoped, so a current library must be set in the CLI config before it can run.

Source

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

				Cell::new(&space.icon),
				Cell::new(&space.color),
				Cell::new(space.order),
			]);
		}

		println!("{table}");
	}

	Ok(())
}

async fn get_layout(ctx: &Context, space_id: String) -> Result<()> {
	use sd_core::ops::spaces::{SpaceLayoutQuery, SpaceLayoutQueryInput};
	use uuid::Uuid;

	let library_id = ctx
		.library_id
		.ok_or_else(|| anyhow::anyhow!("No library selected"))?;

	let space_uuid = Uuid::parse_str(&space_id)?;

	let input = SpaceLayoutQueryInput {
		space_id: space_uuid,
	};
	let response: serde_json::Value = ctx.core.query(&input, Some(library_id)).await?;

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

	Ok(())
}

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Run 'sd library list' and 'sd library switch <id>' to set a current library
  2. Create a library first if none exists ('sd library create')
  3. Then re-run 'sd spaces layout <space_id>'
Defensive patterns

Strategy: validation

Validate before calling

let Some(library_id) = ctx.get_current_library_id() else {
    eprintln!("No current library. Run '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 layout <space_id>' before any 'sd library create'/'sd library switch'; config reset or stale after the referenced library was removed.

Common situations: Fresh install; scripting a sequence of commands where the library switch step was skipped or failed earlier.

Related errors


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