on master help sign in
Improve error message handling for theme loading failures (#5073)

The error messages for a theme that failed to be deserialized (or otherwise failed to load) were covered up by the context/with_context calls: * The log message for a bad theme configured in config.toml would only say "Failed to deserilaize theme" * Selecting a bad theme via :theme would show "Theme does not exist" With these changes, we let the TOML deserializer errors bubble up, so the error messages can now say the line number of a duplicated key - and that key's name - when a theme fails to load because of a duplicated key. Providing a theme which does not exist to :theme still gives a helpful error message: "No such file or directory."

commitdb939801ebf299f11a6a52bdff7a3c9bfb87fc34 authorMichael Davis <mcarsondavis@gmail.com> dateThu 15 Dec 2022, 02:49 (4 years ago) parent012fc12
2 files changed+3−2
helix-term/src/commands/typed.rs+1−1 helix-view/src/theme.rs+2−1
helix-term/src/commands/typed.rs+1−1
@@ -777,7 +777,7 @@ fn theme(
777777 .editor
778778 .theme_loader
779779 .load(theme_name)
780− .with_context(|| "Theme does not exist")?;
780+ .map_err(|err| anyhow::anyhow!("Could not load theme: {}", err))?;
781781 if !(true_color || theme.is_16_color()) {
782782 bail!("Unsupported theme: theme requires true color support");
783783 }
helix-view/src/theme.rs+2−1
@@ -136,8 +136,9 @@ impl Loader {
136136 // Loads the theme data as `toml::Value` first from the user_dir then in default_dir
137137 fn load_toml(&self, path: PathBuf) -> Result<Value> {
138138 let data = std::fs::read(&path)?;
139+ let value = toml::from_slice(data.as_slice())?;
139140
140− toml::from_slice(data.as_slice()).context("Failed to deserialize theme")
141+ Ok(value)
141142 }
142143
143144 // Returns the path to the theme with the name