From 5b9cc2619491c33b133254770ec2494010c2d016 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 27 Jan 2024 19:37:01 -0500 Subject: [PATCH] Gracefully handle errors when loading themes (#6904) This PR improves the theme loading to gracefully handle when a theme couldn't be loaded. Trying to debug a panic that happens on startup in Nightly. Release Notes: - N/A --- crates/theme/src/registry.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/theme/src/registry.rs b/crates/theme/src/registry.rs index 43f6d5b07e..c90b1c909e 100644 --- a/crates/theme/src/registry.rs +++ b/crates/theme/src/registry.rs @@ -1,9 +1,10 @@ use std::collections::HashMap; use std::sync::Arc; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context, Result}; use gpui::{AssetSource, HighlightStyle, SharedString}; use refineable::Refineable; +use util::ResultExt; use crate::{ try_parse_color, Appearance, AppearanceContent, PlayerColor, PlayerColors, StatusColors, @@ -178,17 +179,21 @@ impl ThemeRegistry { let theme_paths = self .assets .list("themes/") - .unwrap() + .expect("failed to list theme assets") .into_iter() .filter(|path| path.ends_with(".json")); for path in theme_paths { - let theme = self - .assets - .load(&path) - .expect(&format!("Failed to load theme '{path}'")); + let Some(theme) = self.assets.load(&path).log_err() else { + continue; + }; - let theme_family: ThemeFamilyContent = serde_json::from_slice(&theme).unwrap(); + let Some(theme_family) = serde_json::from_slice(&theme) + .with_context(|| format!("failed to parse theme at path \"{path}\"")) + .log_err() + else { + continue; + }; self.insert_user_theme_families([theme_family]); }