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
This commit is contained in:
parent
dfad36f668
commit
5b9cc26194
1 changed files with 12 additions and 7 deletions
|
@ -1,9 +1,10 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use gpui::{AssetSource, HighlightStyle, SharedString};
|
use gpui::{AssetSource, HighlightStyle, SharedString};
|
||||||
use refineable::Refineable;
|
use refineable::Refineable;
|
||||||
|
use util::ResultExt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
try_parse_color, Appearance, AppearanceContent, PlayerColor, PlayerColors, StatusColors,
|
try_parse_color, Appearance, AppearanceContent, PlayerColor, PlayerColors, StatusColors,
|
||||||
|
@ -178,17 +179,21 @@ impl ThemeRegistry {
|
||||||
let theme_paths = self
|
let theme_paths = self
|
||||||
.assets
|
.assets
|
||||||
.list("themes/")
|
.list("themes/")
|
||||||
.unwrap()
|
.expect("failed to list theme assets")
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|path| path.ends_with(".json"));
|
.filter(|path| path.ends_with(".json"));
|
||||||
|
|
||||||
for path in theme_paths {
|
for path in theme_paths {
|
||||||
let theme = self
|
let Some(theme) = self.assets.load(&path).log_err() else {
|
||||||
.assets
|
continue;
|
||||||
.load(&path)
|
};
|
||||||
.expect(&format!("Failed to load theme '{path}'"));
|
|
||||||
|
|
||||||
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]);
|
self.insert_user_theme_families([theme_family]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue