{"record":{"id":"16438cbe2546dc5a","repo":"gitbutlerapp/gitbutler","slug":"could-not-read-settings-e","errorCode":null,"errorMessage":"Could not read settings: {e:?}","messagePattern":"Could not read settings: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-settings/src/watch.rs","lineNumber":96,"sourceCode":"        config_dir: impl AsRef<Path>,\n        customization: Option<serde_json::Value>,\n    ) -> Result<Self> {\n        let config_path = config_dir.as_ref().join(SETTINGS_FILE);\n        let app_settings = AppSettings::load(&config_path, customization.clone())?;\n        let app_settings = Arc::new(RwLock::new(app_settings));\n\n        Ok(Self {\n            config_path,\n            snapshot: app_settings,\n            customization,\n        })\n    }\n\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","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-settings/src/watch.rs#L78-L114","documentation":"`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.","triggerScenarios":"Calling `get()` (or anything reading settings) after another thread panicked while holding the settings write lock, poisoning the RwLock.","commonSituations":"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.","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"],"exampleFix":"// before\nlet settings = watcher.get()?; // fails while poisoned\n// after\nlet settings = watcher.get().or_else(|_| {\n    tracing::warn!(\"settings lock poisoned; recovering last snapshot\");\n    watcher.get_recovering()\n})?;","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match settings.get() {\n    Ok(s) => use(s),\n    Err(e) if format!(\"{e:#}\").contains(\"Could not read settings\") => {\n        tracing::error!(\"settings lock poisoned, restarting state\");\n        restart_or_default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["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"],"tags":["settings","lock","poisoned","concurrency"],"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"}