{"record":{"id":"cb5f294555ad2db0","repo":"spacedriveapp/spacedrive","slug":"no-library-selected-run-sd-library-list-to-see","errorCode":null,"errorMessage":"No library selected. Run 'sd library list' to see available libraries","messagePattern":"No library selected\\. Run 'sd library list' to see available libraries","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/domains/spaces/mod.rs","lineNumber":28,"sourceCode":"\tList,\n\t/// Get space layout\n\tLayout {\n\t\t/// Space ID\n\t\tspace_id: String,\n\t},\n}\n\npub async fn exec(cmd: SpacesCmd, ctx: &Context) -> Result<()> {\n\tmatch cmd {\n\t\tSpacesCmd::List => list_spaces(ctx).await,\n\t\tSpacesCmd::Layout { space_id } => get_layout(ctx, space_id).await,\n\t}\n}\n\nasync fn list_spaces(ctx: &Context) -> Result<()> {\n\t// Get current library ID\n\tlet library_id = ctx.library_id.ok_or_else(|| {\n\t\tanyhow::anyhow!(\"No library selected. Run 'sd library list' to see available libraries\")\n\t})?;\n\n\tprintln!(\"Library ID: {}\", library_id);\n\n\t// Create query input\n\tlet input = SpacesListQueryInput;\n\n\t// Execute query through the client\n\tlet response = ctx.core.query(&input, Some(library_id)).await?;\n\n\tprintln!(\n\t\t\"\\nRaw response: {}\",\n\t\tserde_json::to_string_pretty(&response)?\n\t);\n\n\tlet result: sd_core::ops::spaces::SpacesListOutput = serde_json::from_value(response)\n\t\t.map_err(|e| anyhow::anyhow!(\"Failed to parse response: {}\", e))?;\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/cli/src/domains/spaces/mod.rs#L10-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run 'sd library list' to see existing libraries","Create one with 'sd library create' if none exists, or switch with 'sd library switch'","Re-run 'sd spaces list' once a current library is set"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"match ctx.get_current_library_id() {\n    Some(id) => id,\n    None => {\n        eprintln!(\"No current library. Run 'sd library list' then 'sd library switch <id>'.\");\n        return Ok(());\n    }\n}","typeGuard":"fn has_current_library(ctx: &Context) -> bool {\n    ctx.library_id.is_some()\n}","tryCatchPattern":null,"preventionTips":["Create/switch a library right after install so every library-scoped subcommand works","In scripts, run 'sd library switch' once at the start","Remember ctx.library_id comes from the CLI config's current_library_id, not the daemon"],"tags":["cli","spaces","library","config"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}