diff --git a/crates/settings/src/error.rs b/crates/settings/src/error.rs index b8b97ee773..aa0a5488ec 100644 --- a/crates/settings/src/error.rs +++ b/crates/settings/src/error.rs @@ -38,6 +38,14 @@ pub struct SectionError { pub message: String, } +impl fmt::Display for SectionError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "settings section [{}] was reset to defaults: {}", self.section, self.message) + } +} + +impl std::error::Error for SectionError {} + /// Why the store will not write `config.toml`. #[derive(Debug)] pub enum ReadOnlyReason { diff --git a/crates/settings/tests/recovery.rs b/crates/settings/tests/recovery.rs index f12e116219..a28fa9801b 100644 --- a/crates/settings/tests/recovery.rs +++ b/crates/settings/tests/recovery.rs @@ -47,6 +47,19 @@ fn bad_value_only_resets_its_section() { assert!(config_path(tmp.path()).exists(), "the file is not moved aside"); } +#[test] +fn section_error_displays_its_section_and_message() { + let tmp = tempfile::tempdir().unwrap(); + write_config(tmp.path(), "schema_version = 2\n[appearance]\ntheme = \"sepia\"\n"); + let (_, report) = open_in(tmp.path()); + let error = &report.section_errors[0]; + let text = error.to_string(); + assert!(text.starts_with("settings section [appearance] was reset to defaults: "), "{text}"); + assert!(text.ends_with(&error.message), "{text}"); + let source: &dyn std::error::Error = error; + assert!(source.source().is_none()); +} + #[test] fn many_unknown_keys_load_in_linear_time() { // Each key was once tried against every key accepted before it.