gitbutlerapp/gitbutler · error

Could not write settings

Error message

Could not write settings: {e:?}

What it means

`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.

Solutions

  1. Fix the root-cause panic in the settings write path found in logs
  2. Restart the app to clear the poisoned lock
  3. Retry the update after addressing the poisoning cause
  4. Harden writers to avoid panicking while holding the write guard (return Result, no unwrap)

Example fix

// before
settings.update_telemetry(true)?;
// after
if let Err(e) = settings.update_telemetry(true) {
    tracing::error!("telemetry update failed: {e:#}"); // includes 'Could not write settings'
}
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = settings.update_feature_flags(&flags) {
    let msg = format!("{e:#}");
    if msg.contains("Could not write settings") {
        tracing::error!("settings poisoned: {msg}"); // schedule retry after restart
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/a6e6137eff49ba7d. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-settings/src/watch.rs:109

    /// Return a reference to the most recently loaded [`AppSettings`].
    pub fn get(&self) -> Result<RwLockReadGuard<'_, AppSettings>> {
        self.snapshot
            .read()
            .map_err(|e| anyhow::anyhow!("Could not read settings: {e:?}"))
    }

    /// Allow changes only from within this crate to implement all possible settings updates [here](crate::api).
    pub(crate) fn get_mut_enforce_save(&self) -> Result<AppSettingsEnforceSaveToDisk<'_>> {
        self.snapshot
            .write()
            .map(|snapshot| AppSettingsEnforceSaveToDisk {
                snapshot,
                config_path: &self.config_path,
                saved: false,
                customization: self.customization.clone(),
            })
            .map_err(|e| anyhow::anyhow!("Could not write settings: {e:?}"))
    }

    /// The path from which application settings will be read from disk.
    pub fn config_path(&self) -> &Path {
        &self.config_path
    }

    /// Start watching [`Self::config_path()`] for changes and inform
    pub fn watch_in_background(
        &mut self,
        send_event: impl Fn(AppSettings) -> Result<()> + Send + Sync + 'static,
    ) -> Result<()> {
        let (tx, rx) = mpsc::channel();
        let snapshot = self.snapshot.clone();
        let config_path = self.config_path.to_owned();
        let customization = self.customization.clone();
        let watcher_config = Config::default()
            .with_compare_contents(true)

View on GitHub (pinned to 58e5313667)