{"record":{"id":"535341e97b3ee893","repo":"0x192/universal-android-debloater","slug":"unable-to-write-file","errorCode":null,"errorMessage":"Unable to write file","messagePattern":"Unable to write file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/uad_lists.rs","lineNumber":189,"sourceCode":"        )\n    }\n}\n\ntype PackageHashMap = HashMap<String, Package>;\npub fn load_debloat_lists(remote: bool) -> (Result<PackageHashMap, PackageHashMap>, bool) {\n    let cached_uad_lists: PathBuf = CACHE_DIR.join(\"uad_lists.json\");\n    let mut error = false;\n    let list: Vec<Package> = if remote {\n        retry(Fixed::from_millis(1000).take(60), || {\n            match ureq::get(\n                \"https://raw.githubusercontent.com/0x192/universal-android-debloater/\\\n           main/resources/assets/uad_lists.json\",\n            )\n            .call()\n            {\n                Ok(data) => {\n                    let text = data.into_string().expect(\"response should be Ok type\");\n                    fs::write(cached_uad_lists.clone(), &text).expect(\"Unable to write file\");\n                    let list = serde_json::from_str(&text).expect(\"Unable to parse\");\n                    OperationResult::Ok(list)\n                }\n                Err(e) => {\n                    warn!(\"Could not load remote debloat list: {}\", e);\n                    error = true;\n                    OperationResult::Retry(Vec::<Package>::new())\n                }\n            }\n        })\n        .map_or_else(|_| get_local_lists(), |list| list)\n    } else {\n        warn!(\"Could not load remote debloat list\");\n        get_local_lists()\n    };\n\n    // TODO: Do it without intermediary Vec?\n    let mut package_lists = HashMap::new();","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/0x192/universal-android-debloater/blob/11f27c671cba278d71296cdef4c5a5dba06add5e/src/core/uad_lists.rs#L171-L207","documentation":"After downloading the debloat list, the code writes the text to the cached file (CACHE_DIR/uad_lists.json) with fs::write(...).expect(\"Unable to write file\"). A filesystem failure (missing cache directory, permissions, full disk) panics the application even though the download itself succeeded.","triggerScenarios":"CACHE_DIR/uad (cache directory) does not exist or is unwritable when load_debloat_lists runs; disk full; antivirus/OS locking the file on Windows.","commonSituations":"First run where setup_uad_dir failed or was skipped; user cache dir redirected to a read-only location; low disk space; AppArmor/sandbox blocking the cache path.","solutions":["Ensure the cache directory exists (create_dir_all on CACHE_DIR) before writing","Check permissions and free disk space on the cache location","Match on fs::write result and fall back to the bundled/embedded list instead of panicking","Log and degrade gracefully: keep the in-memory list (it parses fine) even if caching fails"],"exampleFix":"// before\nfs::write(cached_uad_lists.clone(), &text).expect(\"Unable to write file\");\n// after\nlet _ = fs::create_dir_all(cached_uad_lists.parent().unwrap());\nif let Err(e) = fs::write(cached_uad_lists.clone(), &text) {\n    warn!(\"Unable to write cache file: {}\", e);\n}","handlingStrategy":"validation","validationCode":"let cache = dirs::cache_dir().unwrap().join(\"uad\");\nstd::fs::create_dir_all(&cache)?;\nlet test = cache.join(\".write_test\");\nstd::fs::write(&test, b\"ok\")?;\nstd::fs::remove_file(&test)?; // cache dir is writable","typeGuard":"fn cache_writable(dir: &std::path::Path) -> bool {\n    dir.exists() && std::fs::metadata(dir)\n        .map(|m| !m.permissions().readonly())\n        .unwrap_or(false)\n}","tryCatchPattern":"let result = std::panic::catch_unwind(|| load_debloat_lists());\nif result.is_err() {\n    eprintln!(\"Unable to write file — check cache dir permissions/disk space\");\n}","preventionTips":["Ensure setup_uad_dir runs successfully before any cache write","Point the cache at a user-writable directory","Keep free disk space on the cache volume","Exclude the cache dir from aggressive antivirus file locks"],"tags":["rust","filesystem","cache","panic"],"backgroundTag":"file-write-permission-denied","analyzedSha":"11f27c671cba278d71296cdef4c5a5dba06add5e","analyzedAt":"2026-09-02T16:12:43.433Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}