{"record":{"id":"6c669f29ffe47626","repo":"0x192/universal-android-debloater","slug":"can-t-create-cache-directory","errorCode":null,"errorMessage":"Can't create cache directory","messagePattern":"Can't create cache directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/utils.rs","lineNumber":65,"sourceCode":"            PackageRow::new(p_name, state, description, uad_list, removal, false, false);\n        user_package.push(package_row);\n    }\n    user_package.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase()));\n    user_package\n}\n\npub fn string_to_theme(theme: &str) -> Theme {\n    match theme {\n        \"Dark\" => Theme::Dark,\n        \"Light\" => Theme::Light,\n        \"Lupin\" => Theme::Lupin,\n        _ => Theme::Lupin,\n    }\n}\n\npub fn setup_uad_dir(dir: Option<PathBuf>) -> PathBuf {\n    let dir = dir.unwrap().join(\"uad\");\n    fs::create_dir_all(&dir).expect(\"Can't create cache directory\");\n    dir\n}\n\npub fn open_url(dir: PathBuf) {\n    #[cfg(target_os = \"windows\")]\n    let output = Command::new(\"explorer\").args([dir]).output();\n\n    #[cfg(target_os = \"macos\")]\n    let output = Command::new(\"open\").args([dir]).output();\n\n    #[cfg(not(any(target_os = \"macos\", target_os = \"windows\")))]\n    let output = Command::new(\"xdg-open\").args([dir]).output();\n\n    match output {\n        Ok(o) => {\n            if !o.status.success() {\n                let stderr = String::from_utf8(o.stderr).unwrap().trim_end().to_string();\n                error!(\"Can't open the following URL: {}\", stderr);","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/0x192/universal-android-debloater/blob/11f27c671cba278d71296cdef4c5a5dba06add5e/src/core/utils.rs#L47-L83","documentation":"setup_uad_dir takes an Option<PathBuf> base directory, calls unwrap() on it, appends \"uad\", and creates the directory tree with fs::create_dir_all(...).expect(\"Can't create cache directory\"). The panic occurs when the base dir is None (unwrap panic) or when directory creation fails due to permissions, an invalid path, read-only filesystem, or I/O errors.","triggerScenarios":"Called with None (dir.unwrap() panics) or with a base path the process cannot create (e.g. CONFIG_DIR/CACHE_DIR parent missing, permission denied, path too long or invalid characters).","commonSituations":"Flatpak/snap or Windows Program Files installs where the chosen data dir is not writable; HOME unset or redirected; the user selected an unwritable folder for cache; antivirus blocking directory creation.","solutions":["Always pass Some(valid_base_dir) pointing at a user-writable location (e.g. dirs::cache_dir()/data_dir())","Check/fix permissions on the base directory, or pick another writable location","Create parent directories first and handle create_dir_all's Result instead of expect()","Return Result<PathBuf, io::Error> and show a setup error in the GUI rather than panicking"],"exampleFix":"// before\nlet dir = dir.unwrap().join(\"uad\");\nfs::create_dir_all(&dir).expect(\"Can't create cache directory\");\n// after\nlet dir = dir.unwrap_or_else(|| dirs::cache_dir().unwrap_or_else(|| \".\".into())).join(\"uad\");\nfs::create_dir_all(&dir).unwrap_or_else(|e| {\n    panic!(\"Can't create cache directory {}: {}\", dir.display(), e)\n})","handlingStrategy":"try-catch","validationCode":"// Ensure a writable base dir exists before the app creates its cache dir\nlet base = dirs::cache_dir().expect(\"no usable base dir\");\nstd::fs::create_dir_all(&base)?;\nlet probe = base.join(\".probe\");\nstd::fs::write(&probe, b\"x\")?;\nstd::fs::remove_file(&probe)?;","typeGuard":"fn base_dir_usable(dir: &Option<std::path::PathBuf>) -> bool {\n    match dir {\n        Some(p) => p.is_dir() && std::fs::metadata(p)\n            .map(|m| !m.permissions().readonly()).unwrap_or(false),\n        None => false,\n    }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(|| setup_uad_dir(Some(base_dir.clone())));\nmatch result {\n    Ok(dir) => dir,\n    Err(_) => { eprintln!(\"Can't create cache directory — pick a writable location\"); std::env::temp_dir() }\n}","preventionTips":["Pass a known-writable base dir (dirs::cache_dir()/data_dir()), never None","Create parent directories before first run (installer step)","Check permissions when running in sandboxed/flatpak environments","Test cache creation on a fresh profile to catch path problems early"],"tags":["rust","filesystem","cache","panic"],"backgroundTag":"directory-create-permission-denied","analyzedSha":"11f27c671cba278d71296cdef4c5a5dba06add5e","analyzedAt":"2026-09-02T16:12:43.433Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}