{"record":{"id":"a6e6137eff49ba7d","repo":"gitbutlerapp/gitbutler","slug":"could-not-write-settings-e","errorCode":null,"errorMessage":"Could not write settings: {e:?}","messagePattern":"Could not write settings: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-settings/src/watch.rs","lineNumber":109,"sourceCode":"\n    /// Return a reference to the most recently loaded [`AppSettings`].\n    pub fn get(&self) -> Result<RwLockReadGuard<'_, AppSettings>> {\n        self.snapshot\n            .read()\n            .map_err(|e| anyhow::anyhow!(\"Could not read settings: {e:?}\"))\n    }\n\n    /// Allow changes only from within this crate to implement all possible settings updates [here](crate::api).\n    pub(crate) fn get_mut_enforce_save(&self) -> Result<AppSettingsEnforceSaveToDisk<'_>> {\n        self.snapshot\n            .write()\n            .map(|snapshot| AppSettingsEnforceSaveToDisk {\n                snapshot,\n                config_path: &self.config_path,\n                saved: false,\n                customization: self.customization.clone(),\n            })\n            .map_err(|e| anyhow::anyhow!(\"Could not write settings: {e:?}\"))\n    }\n\n    /// The path from which application settings will be read from disk.\n    pub fn config_path(&self) -> &Path {\n        &self.config_path\n    }\n\n    /// Start watching [`Self::config_path()`] for changes and inform\n    pub fn watch_in_background(\n        &mut self,\n        send_event: impl Fn(AppSettings) -> Result<()> + Send + Sync + 'static,\n    ) -> Result<()> {\n        let (tx, rx) = mpsc::channel();\n        let snapshot = self.snapshot.clone();\n        let config_path = self.config_path.to_owned();\n        let customization = self.customization.clone();\n        let watcher_config = Config::default()\n            .with_compare_contents(true)","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-settings/src/watch.rs#L91-L127","documentation":"`Settings::get_mut_enforce_save()` acquires the write lock to produce an AppSettingsEnforceSaveToDisk guard; if `write()` fails because the RwLock was poisoned (a panic occurred while another writer held it), the poisoning error is wrapped in this message.","triggerScenarios":"Calling update_onboarding_complete, update_telemetry, update_telemetry_distinct_id, update_feature_flags, update_reviews, or update_fetch after a panic occurred in another thread while a settings write guard was held.","commonSituations":"A previous settings write panicked (e.g. during serialization or the enforced save-to-disk), poisoning the lock; subsequent telemetry/onboarding updates all fail with this error until restart.","solutions":["Fix the root-cause panic in the settings write path found in logs","Restart the app to clear the poisoned lock","Retry the update after addressing the poisoning cause","Harden writers to avoid panicking while holding the write guard (return Result, no unwrap)"],"exampleFix":"// before\nsettings.update_telemetry(true)?;\n// after\nif let Err(e) = settings.update_telemetry(true) {\n    tracing::error!(\"telemetry update failed: {e:#}\"); // includes 'Could not write settings'\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = settings.update_feature_flags(&flags) {\n    let msg = format!(\"{e:#}\");\n    if msg.contains(\"Could not write settings\") {\n        tracing::error!(\"settings poisoned: {msg}\"); // schedule retry after restart\n    }\n}","preventionTips":["Avoid panicking inside settings update callbacks","Persist settings via fallible I/O with error propagation","Test settings writers under panic injection","Restart cleanly on poisoned-lock errors"],"tags":["settings","lock","poisoned","write"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}