{"record":{"id":"e6c2276878729bb7","repo":"spacedriveapp/spacedrive","slug":"failed-to-create-libraries-directory","errorCode":null,"errorMessage":"Failed to create libraries directory: {}","messagePattern":"Failed to create libraries directory: (.+?)","errorType":"exception","errorClass":"LibraryError","httpStatus":null,"severity":"error","filePath":"core/src/library/manager.rs","lineNumber":186,"sourceCode":"\t\t\treturn Err(LibraryError::InvalidName(\n\t\t\t\t\"Name cannot be empty\".to_string(),\n\t\t\t));\n\t\t}\n\n\t\t// Sanitize name for filesystem\n\t\tlet safe_name = sanitize_filename(&name);\n\n\t\t// Use default library location\n\t\tlet base_path = self.search_paths.first().cloned().unwrap_or_else(|| {\n\t\t\tdirs::home_dir()\n\t\t\t\t.unwrap_or_else(|| PathBuf::from(\".\"))\n\t\t\t\t.join(\"Spacedrive\")\n\t\t\t\t.join(\"Libraries\")\n\t\t});\n\n\t\t// Ensure base path exists\n\t\ttokio::fs::create_dir_all(&base_path).await.map_err(|e| {\n\t\t\tLibraryError::IoError(std::io::Error::new(\n\t\t\t\tstd::io::ErrorKind::Other,\n\t\t\t\tformat!(\"Failed to create libraries directory: {}\", e),\n\t\t\t))\n\t\t})?;\n\n\t\t// Find unique library path\n\t\tlet library_path = find_unique_library_path(&base_path, &safe_name).await?;\n\n\t\t// Create library directory\n\t\ttokio::fs::create_dir_all(&library_path).await?;\n\n\t\t// Initialize library with provided UUID (instead of generating new one)\n\t\tself.initialize_library_with_id(\n\t\t\t&library_path,\n\t\t\tlibrary_id,\n\t\t\tname,\n\t\t\tdescription,\n\t\t\tcontext.clone(),","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/library/manager.rs#L168-L204","documentation":"create_library_with_id failed to create the base directory for libraries with tokio::fs::create_dir_all. The base path is the first configured search path, falling back to ~/Spacedrive/Libraries. The message wraps the OS error, but the original io::ErrorKind is discarded in favor of ErrorKind::Other, so parse the formatted text for the real cause.","triggerScenarios":"The daemon user lacks write permission on the base path or its parent; the configured search path points to an unmounted or read-only volume; disk full or quota exceeded; dirs::home_dir() failed and the '.' fallback is not writable.","commonSituations":"Running as a service user without a real home directory; containers and sandboxes with restrictive mounts; NFS or removable media as the library location.","solutions":["Verify the daemon user can create the base path (fix ownership or mode on the parent directory)","Check that the first configured search path exists, is mounted, and is writable, or configure a valid one","Free disk space or raise the quota","Preserve the original error kind when wrapping so PermissionDenied is distinguishable from other IO failures"],"exampleFix":"// before\nLibraryError::IoError(std::io::Error::new(std::io::ErrorKind::Other, format!(\"Failed to create libraries directory: {}\", e)))\n\n// after\nLibraryError::IoError(std::io::Error::new(e.kind(), format!(\"Failed to create libraries directory: {}\", e)))","handlingStrategy":"validation","validationCode":"// Verify the base location is creatable and writable before creating a library\nlet base = search_paths.first().cloned().unwrap_or_else(|| dirs::home_dir().unwrap_or_else(|| PathBuf::from(\".\")).join(\"Spacedrive\").join(\"Libraries\"));\ntokio::fs::create_dir_all(&base).await?;\nlet probe = base.join(\".write-test\");\ntokio::fs::write(&probe, b\"x\").await?;\ntokio::fs::remove_file(&probe).await?;","typeGuard":null,"tryCatchPattern":"match manager.create_library_with_id(id, name, desc, ctx).await {\n    Err(LibraryError::IoError(e)) if e.to_string().contains(\"Failed to create libraries directory\") => {\n        // surface a targeted message: check permissions, mount status, and disk space\n    }\n    other => other,\n}","preventionTips":["Point the first search path at a directory the daemon user can write to","Probe base-path writability at daemon startup, before accepting library creation","Preserve the original io::ErrorKind when wrapping so PermissionDenied is detectable"],"tags":["filesystem","io","permissions","library"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}