spacedriveapp/spacedrive · error
No library selected. Use client.switchToLibrary() first.
Error message
No library selected. Use client.switchToLibrary() first.
What it means
Returned by ConduitService::get_conduit_by_uuid(uuid) when no sync_conduit row matches the uuid filter. This is the UUID-keyed variant of the by-id lookup, used when clients address conduits by their public UUID (set via Uuid::new_v4() at creation) rather than the numeric id.
Source
Thrown at packages/ts-client/src/hooks/useMutation.ts:91
Extract<LibraryAction, { type: T }>["output"],
Error,
Extract<LibraryAction, { type: T }>["input"]
>,
"mutationFn"
>
): UseMutationResult<
Extract<LibraryAction, { type: T }>["output"],
Error,
Extract<LibraryAction, { type: T }>["input"]
> {
const client = useSpacedriveClient();
const wireMethod = WIRE_METHODS.libraryActions[type]; // ← Auto-generated!
return useMutation({
mutationFn: (input) => {
const libraryId = client.getCurrentLibraryId();
if (!libraryId) {
throw new Error("No library selected. Use client.switchToLibrary() first.");
}
// Client.execute() automatically adds library_id to the request
// as a sibling field (not inside payload)
return client.execute(wireMethod, input);
},
...options,
}) as UseMutationResult<
Extract<LibraryAction, { type: T }>["output"],
Error,
Extract<LibraryAction, { type: T }>["input"]
>;
}
View on GitHub (pinned to 6dfeccf211)
Solutions
- Verify the exact UUID: SELECT id, uuid FROM sync_conduit WHERE uuid = '<uuid>';.
- Confirm the UUID round-trips unchanged from the client (no truncation, case/normalization is handled by Uuid parsing).
- If the conduit was deleted, re-create it and update the stored reference.
Defensive patterns
Strategy: validation
Validate before calling
// Validate the reference shape before hitting the DB.
fn is_valid_conduit_uuid(s: &str) -> bool {
uuid::Uuid::parse_str(s).is_ok()
} Type guard
fn is_conduit_uuid(v: &serde_json::Value) -> bool {
v.as_str().map(uuid::Uuid::parse_str).map(|r| r.is_ok()).unwrap_or(false)
} Try / catch
match svc.get_conduit_by_uuid(uuid).await {
Ok(c) => Ok(c),
Err(e) if e.to_string() == "Conduit not found" => {
// stale external reference: log, clear cached uuid, prompt re-selection
clear_cached_conduit_uuid(uuid);
Err(e)
}
Err(e) => Err(e),
} Prevention
- Parse/validate UUID strings at the API boundary before converting to Uuid.
- Store conduit UUIDs only from create_conduit's returned model, never hand-typed.
- Clean up persisted UUID references when conduits are deleted.
When it happens
Trigger: Calling get_conduit_by_uuid with a UUID that is not in the sync_conduit table — malformed/truncated UUID string parsed into a Uuid, a conduit from another library, or a deleted conduit.
Common situations: UUID copied with a missing segment (still parses as nil/other value in some paths), stale references in client state after deletion, cross-library reference leaks.
Related errors
- Unexpected response: ${JSON.stringify(response)}
- No library selected. Use client.switchToLibrary() first.
- Library with ID '${libraryId}' not found
- Library '{}' not found
- No library selected. Use 'sd library switch' to select a lib
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/dcba0bdbe6d5bb8c.
Report an issue: GitHub.