Universal-Debloater-Alliance/universal-android-debloater-next-generation · critical

Can't detect config dir

Error message

Can't detect config dir

What it means

CONFIG_DIR is a LazyLock that calls dirs::config_dir(); if the OS config directory cannot be determined (None), expect panics with "Can't detect config dir". This happens at first access of CONFIG_DIR, typically during app startup.

Solutions

  1. Set HOME to an existing writable directory (Linux/macOS) before launching.
  2. Set XDG_CONFIG_HOME explicitly to a writable path.
  3. If running as a service user, give it a home dir (usermod -m) or run with Environment=HOME=...
  4. Check in code: std::env::var("HOME")/dirs::config_dir() before initializing, and fail with a clear message.

Example fix

// before
let dir = dirs::config_dir().expect("Can't detect config dir");
// after
let dir = dirs::config_dir().unwrap_or_else(|| {
    std::env::var("HOME").map(PathBuf::from).unwrap_or_else(|_| PathBuf::from("/tmp"))
});
Defensive patterns

Strategy: validation

Validate before calling

let ok = std::env::var("XDG_CONFIG_HOME").map(|v| !v.is_empty()).unwrap_or(false)
    || std::env::var("HOME").map(|v| !v.is_empty()).unwrap_or(false);
if !ok { return Err("cannot determine config dir: set HOME or XDG_CONFIG_HOME"); }

Type guard

fn config_dir_available() -> bool { dirs::config_dir().is_some() }

Try / catch

let dir = std::panic::catch_unwind(|| uad_core::CONFIG_DIR.clone())
    .unwrap_or_else(|_| { eprintln!("no config dir: set HOME or XDG_CONFIG_HOME"); std::process::exit(1); });

Prevention

When it happens

Trigger: First read of uad_core::CONFIG_DIR when dirs::config_dir() returns None — on Linux/Windows this means XDG_CONFIG_HOME unset or empty and $HOME unset or empty (or similar on other platforms).

Common situations: Running under systemd units, cron, Docker, or CI without HOME set; running as a system user with no home directory; stripped environment variables.

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/3de6b902faad1033. Report an issue: GitHub.

Appendix: source

Thrown at crates/uad-core/src/lib.rs:21

    clippy::missing_errors_doc,
    clippy::collapsible_if,
    clippy::uninlined_format_args,
    clippy::result_unit_err,
    reason = "Doc+style pedantic lints are out-of-scope for this pass"
)]

pub mod adb;
pub mod config;
pub mod save;
pub mod sync;
pub mod uad_lists;
pub mod update;
pub mod utils;

use std::path::PathBuf;
use std::sync::LazyLock;
pub static CONFIG_DIR: LazyLock<PathBuf> =
    LazyLock::new(|| utils::setup_uad_dir(&dirs::config_dir().expect("Can't detect config dir")));
pub static CACHE_DIR: LazyLock<PathBuf> =
    LazyLock::new(|| utils::setup_uad_dir(&dirs::cache_dir().expect("Can't detect cache dir")));

View on GitHub (pinned to 64465c850c)