0x192/universal-android-debloater · error

Could not write config file to disk!

Error message

Could not write config file to disk!

What it means

Config::save_changes serializes the app Config struct to TOML and writes it to the static CONFIG_FILE path (CONFIG_DIR/config.toml) using fs::write(...).expect(...). The panic means the filesystem write failed: the config directory does not exist, is not writable, or an OS-level I/O error occurred. Because expect() is used instead of error propagation, the whole application thread panics on failure.

Source

Thrown at src/core/config.rs:70

#[dynamic]
static CONFIG_FILE: PathBuf = CONFIG_DIR.join("config.toml");

impl Config {
    pub fn save_changes(settings: &Settings, device_id: &String) {
        let mut config = Self::load_configuration_file();
        if let Some(device) = config
            .devices
            .iter_mut()
            .find(|x| x.device_id == *device_id)
        {
            *device = settings.device.clone();
        } else {
            debug!("config: New device settings saved");
            config.devices.push(settings.device.clone());
        }
        config.general = settings.general.clone();
        let toml = toml::to_string(&config).unwrap();
        fs::write(&*CONFIG_FILE, toml).expect("Could not write config file to disk!");
    }

    pub fn load_configuration_file() -> Self {
        match fs::read_to_string(&*CONFIG_FILE) {
            Ok(s) => match toml::from_str(&s) {
                Ok(config) => return config,
                Err(e) => error!("Invalid config file: `{}`", e),
            },
            Err(e) => error!("Failed to read config file: `{}`", e),
        }
        error!("Restoring default config file");
        let toml = toml::to_string(&Self::default()).unwrap();
        fs::write(&*CONFIG_FILE, toml).expect("Could not write config file to disk!");
        Self::default()
    }
}

View on GitHub (pinned to 11f27c671c)

Solutions

  1. Ensure the config directory exists before writing (fs::create_dir_all on CONFIG_DIR's parent) in setup/startup code
  2. Check permissions on the config file and its directory (ls -l; chown/chmod so the running user can write)
  3. Free disk space or fix the underlying I/O error reported by the OS
  4. Replace expect() with proper error handling so a failed save shows a message instead of panicking

Example fix

// before
fs::write(&*CONFIG_FILE, toml).expect("Could not write config file to disk!");
// after
if let Some(parent) = CONFIG_FILE.parent() { let _ = fs::create_dir_all(parent); }
if let Err(e) = fs::write(&*CONFIG_FILE, toml) {
    error!("Could not write config file to disk: {}", e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust caller-side check before triggering a settings save
fn config_writable(file: &std::path::Path) -> bool {
    if let Some(parent) = file.parent() {
        if !parent.exists() && std::fs::create_dir_all(parent).is_err() { return false; }
    }
    match std::fs::OpenOptions::new().write(true).create(true).open(file) {
        Ok(_) => true,
        Err(e) => { eprintln!("config not writable: {}", e); false }
    }
}

Type guard

fn config_file_writable(file: &std::path::Path) -> bool {
    std::fs::metadata(file)
        .map(|m| !m.permissions().readonly())
        .unwrap_or(false)
        && file.parent().map(|p| p.exists()).unwrap_or(false)
}

Try / catch

// Rust: catch_unwind around the panicking API, or prefer upstream fix
let result = std::panic::catch_unwind(|| Config::save_changes(&settings, &device_id));
match result {
    Ok(_) => println!("saved"),
    Err(_) => eprintln!("Could not write config file to disk! Check permissions/disk."),
}

Prevention

When it happens

Trigger: Calling save_changes after changing settings when CONFIG_DIR was deleted or never created, the disk is full, the path is read-only, or the user lacks write permission on the config file/directory.

Common situations: Users running the app from a read-only mount or with a relocated/locked HOME dir; permission changes on ~/.config; full disk after a large download; sandboxed/flatpak environments where CONFIG_DIR points outside the allowed sandbox.

Related errors


AI-assisted analysis of 0x192/universal-android-debloater@11f27c671c (2026-09-02). Data as JSON: /api/errors/9b00ad858606869f. Report an issue: GitHub.