Indicate the key-path to the error when failing to load a theme

Max Brunsfeld created

Change summary

Cargo.lock                      | 1 +
zed/Cargo.toml                  | 1 +
zed/src/theme/theme_registry.rs | 7 +++----
3 files changed, 5 insertions(+), 4 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -5835,6 +5835,7 @@ dependencies = [
  "seahash",
  "serde 1.0.125",
  "serde_json 1.0.64",
+ "serde_path_to_error",
  "similar",
  "simplelog",
  "smallvec",

zed/Cargo.toml 🔗

@@ -42,6 +42,7 @@ rust-embed = "5.9.0"
 seahash = "4.1"
 serde = { version = "1", features = ["derive"] }
 serde_json = { version = "1.0.64", features = ["preserve_order"] }
+serde_path_to_error = "0.1.4"
 similar = "1.3"
 simplelog = "0.9"
 smallvec = { version = "1.6", features = ["union"] }

zed/src/theme/theme_registry.rs 🔗

@@ -1,8 +1,7 @@
 use anyhow::{anyhow, Context, Result};
 use gpui::{fonts, AssetSource, FontCache};
-use json::{Map, Value};
 use parking_lot::Mutex;
-use serde_json as json;
+use serde_json::{Map, Value};
 use std::{collections::HashMap, fmt, mem, sync::Arc};
 
 use super::Theme;
@@ -71,8 +70,8 @@ impl ThemeRegistry {
         }
 
         let theme_data = self.load(name, true)?;
-        let mut theme = fonts::with_font_cache(self.font_cache.clone(), || {
-            serde_json::from_value::<Theme>(theme_data.as_ref().clone())
+        let mut theme: Theme = fonts::with_font_cache(self.font_cache.clone(), || {
+            serde_path_to_error::deserialize(theme_data.as_ref())
         })?;
 
         theme.name = name.into();