{"record":{"id":"5e49276c44f3b986","repo":"Universal-Debloater-Alliance/universal-android-debloater-next-generation","slug":"could-not-write-config-file-to-disk","errorCode":null,"errorMessage":"Could not write config file to disk!","messagePattern":"Could not write config file to disk!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/uad-core/src/config.rs","lineNumber":75,"sourceCode":"\nimpl Config {\n    pub fn save_device_settings(\n        &mut self,\n        device_settings: DeviceSettings,\n        general: GeneralSettings,\n    ) {\n        if let Some(device) = self\n            .devices\n            .iter_mut()\n            .find(|x| x.device_id == device_settings.device_id)\n        {\n            *device = device_settings;\n        } else {\n            self.devices.push(device_settings);\n        }\n        self.general = general;\n        let toml = toml::to_string(&self).unwrap();\n        fs::write(&*CONFIG_FILE, toml).expect(\"Could not write config file to disk!\");\n    }\n\n    #[must_use]\n    pub fn load_configuration_file() -> Self {\n        match fs::read_to_string(&*CONFIG_FILE) {\n            Ok(s) => match toml::from_str(&s) {\n                Ok(config) => return config,\n                Err(e) => error!(\"Invalid config file: `{e}`\"),\n            },\n            Err(e) => error!(\"Failed to read config file: `{e}`\"),\n        }\n        error!(\"Restoring default config file\");\n        let toml = toml::to_string(&Self::default()).unwrap();\n        fs::write(&*CONFIG_FILE, toml).expect(\"Could not write config file to disk!\");\n        Self::default()\n    }\n}\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/64465c850c7ed36329e67165ac08501abffb218e/crates/uad-core/src/config.rs#L57-L93","documentation":"save_device_settings serializes the whole config to TOML and writes it to CONFIG_FILE; if fs::write fails it panics with \"Could not write config file to disk!\". The library treats inability to persist settings as a hard failure, raised on every settings-mutating handler.","triggerScenarios":"Calling save_device_settings (via handle_expert_mode, handle_disable_mode, handle_multi_user_mode, handle_apply_theme, handle_folder_chosen) when CONFIG_FILE cannot be written: parent dir missing/locked, read-only filesystem, disk full, or permission denied.","commonSituations":"Read-only $HOME, flatpak/sandbox blocking the config path, another process holding a mandatory lock, quota exceeded, or CONFIG_DIR setup previously failed.","solutions":["Check write permissions on the config directory and file (ls -l, try touching the file as the same user).","Free disk space / check quota.","If sandboxed (flatpak, snap), grant access to the config path or set a writable XDG_CONFIG_HOME.","Wrap the save call in catch_unwind or patch to return Result and surface a UI error instead of panicking."],"exampleFix":"// before\nfs::write(&*CONFIG_FILE, toml).expect(\"Could not write config file to disk!\");\n// after\nif let Err(e) = fs::write(&*CONFIG_FILE, toml) {\n    error!(\"Could not write config file: {e}\");\n    return; // or propagate a Result::Err to the caller\n}","handlingStrategy":"validation","validationCode":"let cfg_dir = config_file.parent().unwrap_or(std::path::Path::new(\".\"));\nif !cfg_dir.is_dir() { return Err(\"config dir missing\"); }\nlet probe = cfg_dir.join(\".write_test\");\nstd::fs::write(&probe, b\"\").map_err(|e| format!(\"config dir not writable: {e}\"))?;\nlet _ = std::fs::remove_file(&probe);","typeGuard":"fn config_writable(p: &std::path::Path) -> bool {\n    if let Some(d) = p.parent() { d.is_dir() && std::fs::OpenOptions::new().append(true).open(p).or_else(|_| std::fs::OpenOptions::new().write(true).create_new(true).open(d.join(\".probe\"))).is_ok() } else { false }\n}","tryCatchPattern":"std::panic::catch_unwind(|| config.save_device_settings(general, device_settings))\n    .map_err(|_| \"could not write config file to disk\")?;","preventionTips":["Check disk space and write permissions on the config directory regularly.","In flatpak/snap, grant the app access to its config path.","Avoid running the app as a user without a writable HOME.","Prefer a Result-returning save API and surface errors in the UI."],"tags":["filesystem","config","panic","rust"],"backgroundTag":"file-write-failed","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"}