Universal-Debloater-Alliance/universal-android-debloater-next-generation · critical
Can't detect cache dir
Error message
Can't detect cache dir
What it means
At startup, main builds the global CACHE_DIR via `dirs::cache_dir().expect("Can't detect cache dir")`. dirs::cache_dir returns None when the platform's cache-directory convention cannot be resolved (e.g. $XDG_CACHE_HOME unset and $HOME unavailable on Linux). The app treats an unresolvable cache dir as fatal and panics before the GUI starts.
Solutions
- Set the environment before launching: `XDG_CACHE_HOME=/tmp/uad-cache` or ensure `HOME` points at a writable directory (`env HOME=/root ./uad-ng`).
- Fall back to a default (e.g. ./cache or temp_dir()) instead of panicking when dirs::cache_dir() is None.
- When running as a service, configure the unit with `Environment=HOME=/home/user` or use `ExecStart=/usr/bin/env HOME=%h ...`.
- Log the resolved cache path at startup to make misconfiguration visible.
Example fix
// before
static CACHE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
setup_uad_dir(&dirs::cache_dir().expect("Can't detect cache dir"))
});
// after
static CACHE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
setup_uad_dir(&dirs::cache_dir().unwrap_or_else(|| {
std::env::temp_dir().join("uad-ng")
}))
}); Defensive patterns
Strategy: fallback
Validate before calling
// before launching the app
const HOME: &str = "HOME";
const XDG: &str = "XDG_CACHE_HOME";
if std::env::var_os(XDG).is_none()
&& std::env::var_os(HOME).map_or(true, |h| h.is_empty())
{
eprintln!("HOME/XDG_CACHE_HOME unset: cache dir cannot be detected");
} Try / catch
let cache = dirs::cache_dir().unwrap_or_else(|| std::env::temp_dir().join("uad-ng")); Prevention
- Ensure HOME (Linux/macOS) or the user profile (Windows) is set when launching from services/containers.
- Launch via a login shell or a wrapper exporting XDG_CACHE_HOME when running under sudo/cron/systemd.
- Prefer a temp-dir fallback over panicking for a cache location.
When it happens
Trigger: Launching the UAD GUI binary in an environment where dirs::cache_dir() yields None: Linux with $HOME unset (cron, systemd service without User= env, su without login shell, minimal containers), or a Windows profile without a LOCALAPPDATA equivalent.
Common situations: Running the app from a systemd unit or Docker container that doesn't set HOME/XDG_CACHE_HOME; invoking via `sudo -i` strips or alters env; headless CI environments launching the GUI binary for smoke tests.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of Universal-Debloater-Alliance/universal-android-debloater-next-generation@64465c850c (2026-09-12).
Data as JSON: /api/errors/9ff5f790eb67d878.
Report an issue: GitHub.
Appendix: source
Thrown at crates/uad-gui/src/main.rs:15
#![windows_subsystem = "windows"]
use fern::{
FormatCallback,
colors::{Color, ColoredLevelConfig},
};
use log::Record;
use std::sync::LazyLock;
use std::{fmt::Arguments, fs::OpenOptions, path::PathBuf};
use uad_core::utils::setup_uad_dir;
use uad_gui::gui::UadGui;
static CACHE_DIR: LazyLock<PathBuf> =
LazyLock::new(|| setup_uad_dir(&dirs::cache_dir().expect("Can't detect cache dir")));
fn main() -> iced::Result {
// Safety: This function is safe to call in a single-threaded program.
// The exact requirement is: you must ensure that there are no other threads concurrently writing or
// reading(!) the environment through functions or global variables other than the ones in this module.
unsafe {
// Force WGPU/Iced to use discrete GPU to prevent crashes on PCs with two GPUs.
// See #848 and related pull 850.
std::env::set_var("WGPU_POWER_PREF", "high");
}
setup_logger().expect("setup logging");
UadGui::start()
}
/// Sets up logging to a new file in `CACHE_DIR"/uadng.log"`
/// Also attaches the terminal on Windows machines
/// '''View on GitHub (pinned to 64465c850c)