gitbutlerapp/gitbutler · error
Could not read settings
Error message
Could not read settings: {e:?} What it means
`Settings::get()` returns the current AppSettings behind a RwLock; if `read()` on the lock fails (poisoned lock after a panic while holding the write guard) the poisoning error is wrapped in this anyhow message.
Solutions
- Fix the panic that poisoned the lock (check upstream logs for the original panic in a settings writer)
- Restart the application — the poisoned lock cannot be recovered in-process
- Add an inner recoverable lock (e.g. lock().unwrap_or_else(|e| e.into_inner())) if snapshot integrity can be trusted despite a panicking writer
- Audit settings update paths to return Result instead of unwrapping
Example fix
// before
let settings = watcher.get()?; // fails while poisoned
// after
let settings = watcher.get().or_else(|_| {
tracing::warn!("settings lock poisoned; recovering last snapshot");
watcher.get_recovering()
})?; Defensive patterns
Strategy: retry
Try / catch
match settings.get() {
Ok(s) => use(s),
Err(e) if format!("{e:#}").contains("Could not read settings") => {
tracing::error!("settings lock poisoned, restarting state");
restart_or_default()
}
Err(e) => return Err(e),
} Prevention
- Never unwrap while holding settings write guards
- Return Result from all settings mutators
- Monitor for panics in settings-watch threads
- Keep the snapshot lock hold time short
When it happens
Trigger: Calling `get()` (or anything reading settings) after another thread panicked while holding the settings write lock, poisoning the RwLock.
Common situations: A settings-watch thread or update path panicked mid-update (e.g. serialization bug or disk error unwrapped), leaving the snapshot lock poisoned; subsequent get() calls across the app now fail.
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
- Could not write settings
- another pre-commit hook is already using the repository…
- changed while preparing the rewrite; leaving it alone
- diffing-thread crashed
- failed to create app settings
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/16438cbe2546dc5a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-settings/src/watch.rs:96
config_dir: impl AsRef<Path>,
customization: Option<serde_json::Value>,
) -> Result<Self> {
let config_path = config_dir.as_ref().join(SETTINGS_FILE);
let app_settings = AppSettings::load(&config_path, customization.clone())?;
let app_settings = Arc::new(RwLock::new(app_settings));
Ok(Self {
config_path,
snapshot: app_settings,
customization,
})
}
/// 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_pathView on GitHub (pinned to 58e5313667)