theme: Return structured errors when a theme is not found (#25090)
This PR updates the `ThemeRegistry` to return structured errors from the `get` and `get_icon_theme` methods (which are used to retrieve themes and icon themes, respectively). We want to be able to carry the name of the theme that was not found as state on the error, which is why we use a `Result` and not an `Option`. However, we also want to be able to accurately identify when the error case is "not found" so we can take appropriate action, based on the circumstances. By using a custom error type instead of an `anyhow::Error`, we get both. There isn't any functional change in this PR. This just sets us up for future improvements in this error. Release Notes: - N/A
This commit is contained in:
parent
76f501af71
commit
8e7cad7848
4 changed files with 43 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::fallback_themes::zed_default_dark;
|
||||
use crate::{
|
||||
Appearance, IconTheme, SyntaxTheme, Theme, ThemeRegistry, ThemeStyleContent,
|
||||
DEFAULT_ICON_THEME_NAME,
|
||||
Appearance, IconTheme, IconThemeNotFoundError, SyntaxTheme, Theme, ThemeNotFoundError,
|
||||
ThemeRegistry, ThemeStyleContent, DEFAULT_ICON_THEME_NAME,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
|
@ -578,9 +578,14 @@ impl ThemeSettings {
|
|||
|
||||
let mut new_theme = None;
|
||||
|
||||
if let Some(theme) = themes.get(theme).log_err() {
|
||||
self.active_theme = theme.clone();
|
||||
new_theme = Some(theme);
|
||||
match themes.get(theme) {
|
||||
Ok(theme) => {
|
||||
self.active_theme = theme.clone();
|
||||
new_theme = Some(theme);
|
||||
}
|
||||
Err(err @ ThemeNotFoundError(_)) => {
|
||||
log::error!("{err}");
|
||||
}
|
||||
}
|
||||
|
||||
self.apply_theme_overrides();
|
||||
|
@ -838,8 +843,13 @@ impl settings::Settings for ThemeSettings {
|
|||
|
||||
let theme_name = value.theme(*system_appearance);
|
||||
|
||||
if let Some(theme) = themes.get(theme_name).log_err() {
|
||||
this.active_theme = theme;
|
||||
match themes.get(theme_name) {
|
||||
Ok(theme) => {
|
||||
this.active_theme = theme;
|
||||
}
|
||||
Err(err @ ThemeNotFoundError(_)) => {
|
||||
log::error!("{err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -851,8 +861,13 @@ impl settings::Settings for ThemeSettings {
|
|||
|
||||
let icon_theme_name = value.icon_theme(*system_appearance);
|
||||
|
||||
if let Some(icon_theme) = themes.get_icon_theme(icon_theme_name).log_err() {
|
||||
this.active_icon_theme = icon_theme;
|
||||
match themes.get_icon_theme(icon_theme_name) {
|
||||
Ok(icon_theme) => {
|
||||
this.active_icon_theme = icon_theme;
|
||||
}
|
||||
Err(err @ IconThemeNotFoundError(_)) => {
|
||||
log::error!("{err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue