{"record":{"id":"09316d34bb503b98","repo":"Universal-Debloater-Alliance/universal-android-debloater-next-generation","slug":"can-t-detect-cache-dir","errorCode":null,"errorMessage":"Can't detect cache dir","messagePattern":"Can't detect cache dir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/uad-core/src/lib.rs","lineNumber":23,"sourceCode":"    clippy::uninlined_format_args,\n    clippy::result_unit_err,\n    reason = \"Doc+style pedantic lints are out-of-scope for this pass\"\n)]\n\npub mod adb;\npub mod config;\npub mod save;\npub mod sync;\npub mod uad_lists;\npub mod update;\npub mod utils;\n\nuse std::path::PathBuf;\nuse std::sync::LazyLock;\npub static CONFIG_DIR: LazyLock<PathBuf> =\n    LazyLock::new(|| utils::setup_uad_dir(&dirs::config_dir().expect(\"Can't detect config dir\")));\npub static CACHE_DIR: LazyLock<PathBuf> =\n    LazyLock::new(|| utils::setup_uad_dir(&dirs::cache_dir().expect(\"Can't detect cache dir\")));\n","sourceCodeStart":5,"sourceCodeEnd":24,"githubUrl":"https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/64465c850c7ed36329e67165ac08501abffb218e/crates/uad-core/src/lib.rs#L5-L24","documentation":"A panic raised while initializing the CACHE_DIR lazy static at crate load: dirs::cache_dir() returned None, so expect() aborted before the app could start. This happens when the platform provides no user cache directory — e.g. on Linux when neither XDG_CACHE_HOME nor HOME is set (common under service managers, cron, or stripped container environments), since the dirs crate derives the cache path from those variables. Because it fires in a LazyLock on first access to CACHE_DIR, the crash occurs at startup rather than at the call site that uses the path.","triggerScenarios":"First read of uad_core::CACHE_DIR when dirs::cache_dir() returns None — on Linux, XDG_CACHE_HOME unset/empty AND $HOME unset/empty; analogous conditions on other platforms.","commonSituations":"Container or systemd service with no HOME env var, ephemeral CI runners, running as a headless system user, sanitized environment.","solutions":["Set HOME to a writable directory before launching the app.","Set XDG_CACHE_HOME explicitly to a writable path.","Grant the service account a home directory or pass Environment=HOME=... in the unit file.","Pre-check dirs::cache_dir() in your launcher and abort with a friendly message."],"exampleFix":"// before\nlet dir = dirs::cache_dir().expect(\"Can't detect cache dir\");\n// after\nlet dir = dirs::cache_dir().unwrap_or_else(|| {\n    std::env::var(\"XDG_CACHE_HOME\").or_else(|_| std::env::var(\"HOME\")).map(PathBuf::from).unwrap_or_else(|_| PathBuf::from(\"/tmp\"))\n});","handlingStrategy":"validation","validationCode":"let ok = std::env::var(\"XDG_CACHE_HOME\").map(|v| !v.is_empty()).unwrap_or(false)\n    || std::env::var(\"HOME\").map(|v| !v.is_empty()).unwrap_or(false);\nif !ok { return Err(\"cannot determine cache dir: set HOME or XDG_CACHE_HOME\"); }","typeGuard":"fn cache_dir_available() -> bool { dirs::cache_dir().is_some() }","tryCatchPattern":"let dir = std::panic::catch_unwind(|| uad_core::CACHE_DIR.clone())\n    .unwrap_or_else(|_| { eprintln!(\"no cache dir: set HOME or XDG_CACHE_HOME\"); std::process::exit(1); });","preventionTips":["Ensure HOME exists in Docker/systemd/CI environments.","Set XDG_CACHE_HOME to a writable tmpfs or persistent path.","Don't clear environment variables when dropping privileges.","Probe dirs::cache_dir() at startup with a clear failure message."],"tags":["environment","cache","panic","rust","dirs"],"backgroundTag":"missing-env-var","analyzedSha":"64465c850c7ed36329e67165ac08501abffb218e","analyzedAt":"2026-09-12T09:09:23.137Z","contentChangedAt":"2026-09-12T09:09:23.137Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}