{"record":{"id":"9ff5f790eb67d878","repo":"Universal-Debloater-Alliance/universal-android-debloater-next-generation","slug":"can-t-detect-cache-dir-main","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-gui/src/main.rs","lineNumber":15,"sourceCode":"#![windows_subsystem = \"windows\"]\n\nuse fern::{\n    FormatCallback,\n    colors::{Color, ColoredLevelConfig},\n};\nuse log::Record;\nuse std::sync::LazyLock;\nuse std::{fmt::Arguments, fs::OpenOptions, path::PathBuf};\nuse uad_core::utils::setup_uad_dir;\n\nuse uad_gui::gui::UadGui;\n\nstatic CACHE_DIR: LazyLock<PathBuf> =\n    LazyLock::new(|| setup_uad_dir(&dirs::cache_dir().expect(\"Can't detect cache dir\")));\n\nfn main() -> iced::Result {\n    // Safety: This function is safe to call in a single-threaded program.\n    // The exact requirement is: you must ensure that there are no other threads concurrently writing or\n    // reading(!) the environment through functions or global variables other than the ones in this module.\n    unsafe {\n        // Force WGPU/Iced to use discrete GPU to prevent crashes on PCs with two GPUs.\n        // See #848 and related pull 850.\n        std::env::set_var(\"WGPU_POWER_PREF\", \"high\");\n    }\n\n    setup_logger().expect(\"setup logging\");\n    UadGui::start()\n}\n\n/// Sets up logging to a new file in `CACHE_DIR\"/uadng.log\"`\n/// Also attaches the terminal on Windows machines\n/// '''","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/64465c850c7ed36329e67165ac08501abffb218e/crates/uad-gui/src/main.rs#L1-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nstatic CACHE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {\n    setup_uad_dir(&dirs::cache_dir().expect(\"Can't detect cache dir\"))\n});\n// after\nstatic CACHE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {\n    setup_uad_dir(&dirs::cache_dir().unwrap_or_else(|| {\n        std::env::temp_dir().join(\"uad-ng\")\n    }))\n});","handlingStrategy":"fallback","validationCode":"// before launching the app\nconst HOME: &str = \"HOME\";\nconst XDG: &str = \"XDG_CACHE_HOME\";\nif std::env::var_os(XDG).is_none()\n    && std::env::var_os(HOME).map_or(true, |h| h.is_empty())\n{\n    eprintln!(\"HOME/XDG_CACHE_HOME unset: cache dir cannot be detected\");\n}","typeGuard":null,"tryCatchPattern":"let cache = dirs::cache_dir().unwrap_or_else(|| std::env::temp_dir().join(\"uad-ng\"));","preventionTips":["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."],"tags":["panic","startup","environment","cache-dir","linux"],"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"}