Skip to content

Commit eaf9901

Browse files
claudesinelaw
authored andcommitted
fix: Fallback to default theme when configured theme not found
Instead of failing with an error when a theme is not found (e.g., user deletes a downloaded theme), gracefully fall back to the default theme and log a warning.
1 parent cbdd355 commit eaf9901

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

crates/fresh-editor/src/app/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,18 @@ impl Editor {
762762
let theme_loader = crate::view::theme::ThemeLoader::new();
763763
let theme_registry = theme_loader.load_all();
764764

765-
// Get active theme from registry
766-
let theme = theme_registry
767-
.get_cloned(&config.theme)
768-
.ok_or_else(|| anyhow::anyhow!("Theme '{}' not found", config.theme.0))?;
765+
// Get active theme from registry, falling back to default if not found
766+
let theme = theme_registry.get_cloned(&config.theme).unwrap_or_else(|| {
767+
tracing::warn!(
768+
"Theme '{}' not found, falling back to default theme",
769+
config.theme.0
770+
);
771+
theme_registry
772+
.get_cloned(&crate::config::ThemeName(
773+
crate::view::theme::THEME_HIGH_CONTRAST.to_string(),
774+
))
775+
.expect("Default theme must exist")
776+
});
769777

770778
// Set terminal cursor color to match theme
771779
theme.set_terminal_cursor_color();

crates/fresh-editor/tests/e2e/theme.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,17 @@ fn test_theme_loading_from_config_high_contrast() {
7272
}
7373

7474
#[test]
75-
#[ignore = "Theme loading now errors instead of falling back - behavior change from json theme refactor"]
76-
fn test_invalid_theme_falls_back_to_dark() {
75+
fn test_invalid_theme_falls_back_to_default() {
7776
let config = Config {
7877
theme: "nonexistent-theme".into(),
7978
..Default::default()
8079
};
8180

8281
let harness = EditorTestHarness::with_config(80, 24, config).unwrap();
8382

84-
// Should fall back to dark theme
83+
// Should fall back to default theme (high-contrast)
8584
let theme = harness.editor().theme();
86-
assert_eq!(theme.name, "dark");
85+
assert_eq!(theme.name, "high-contrast");
8786
}
8887

8988
#[test]

0 commit comments

Comments
 (0)