{"record":{"id":"f7e7abd2dca603ed","repo":"spacedriveapp/spacedrive","slug":"this-operation-requires-an-active-library-use-swi","errorCode":null,"errorMessage":"This operation requires an active library. Use switchToLibrary() first.","messagePattern":"This operation requires an active library\\. Use switchToLibrary\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ts-client/src/client.ts","lineNumber":171,"sourceCode":"\tasync getCurrentLibraryInfo() {\n\t\tconst libraryId = this.getCurrentLibraryId();\n\t\tif (!libraryId) return null;\n\n\t\tconst libraries = await this.execute<{}, any[]>(\n\t\t\t\"query:libraries.list\",\n\t\t\t{},\n\t\t);\n\t\treturn libraries.find((lib: any) => lib.id === libraryId) ?? null;\n\t}\n\n\t/**\n\t * Require a current library or throw\n\t * @internal\n\t */\n\trequireCurrentLibrary(): string {\n\t\tconst libraryId = this.getCurrentLibraryId();\n\t\tif (!libraryId) {\n\t\t\tthrow new Error(\n\t\t\t\t\"This operation requires an active library. Use switchToLibrary() first.\",\n\t\t\t);\n\t\t}\n\t\treturn libraryId;\n\t}\n\n\t// MARK: - Core Execution Methods\n\n\t/**\n\t * Execute a wire method with the given input\n\t * This is the low-level method used by TanStack Query hooks\n\t */\n\tasync execute<I, O>(wireMethod: string, input: I): Promise<O> {\n\t\t// Determine if this is a query or action based on wire method prefix\n\t\tconst isQuery = wireMethod.startsWith(\"query:\");\n\t\tconst isAction = wireMethod.startsWith(\"action:\");\n\n\t\tif (!isQuery && !isAction) {","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/packages/ts-client/src/client.ts#L153-L189","documentation":"Returned by create_conduit when either endpoint entry exists but is not a directory: the code checks `source.kind != 1 || target.kind != 1`, where kind 1 denotes a directory. Sync conduits recursively walk directory trees (see resolver.rs get_entries_recursive), so file endpoints are rejected up front.","triggerScenarios":"Calling create_conduit where either entry is a file (kind 0) or any non-directory kind — e.g. the user picked a file in the picker, or the entry kind was misclassified during indexing.","commonSituations":"File picker not filtered to folders; drag-and-drop of a file onto a 'sync target' drop zone; entries whose kind field was set incorrectly by a custom import.","solutions":["Check both rows: SELECT id, kind, name FROM entry WHERE id IN (<source>, <target>); both must have kind = 1.","If a directory was misclassified, re-index it so kind is corrected.","In the client, filter the picker to directories (kind == 1) before enabling the create button."],"exampleFix":"// before\nconduits.create_conduit(file_entry.id, target_dir.id, mode, \"*:*\".into()).await?;\n\n// after\nif file_entry.kind != 1 || target_dir.kind != 1 {\n    return Err(anyhow::anyhow!(\"Pick two directories\"));\n}\nconduits.create_conduit(file_entry.id, target_dir.id, mode, \"*:*\".into()).await?;","handlingStrategy":"validation","validationCode":"// kind == 1 means directory in this schema; check before calling create_conduit.\nasync fn is_directory_entry(db: &DatabaseConnection, id: i32) -> Result<bool> {\n    Ok(entry::Entity::find_by_id(id)\n        .one(db)\n        .await?\n        .map(|e| e.kind == 1)\n        .unwrap_or(false))\n}","typeGuard":null,"tryCatchPattern":"match svc.create_conduit(src, tgt, mode, sched).await {\n    Ok(c) => Ok(c),\n    Err(e) if e.to_string().contains(\"must be directories\") => {\n        Err(anyhow::anyhow!(\"select folders, not files\")) // map to a user-facing message\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Filter directory pickers to kind == 1 and disable submit for files.","Centralize the kind==1 constant (e.g. EntryKind::Directory) instead of magic number 1.","Re-verify kind right before submission; kind can change if a path is replaced by a file."],"tags":["rust","file-sync","validation","directories"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}