Skip to content

Commit 9c627c6

Browse files
authored
Improve error handling for config-reload (#3668)
* Don't change config to default when refreshing invalid config * Propely handle theme errors with config-reload * Extract refresh theme into seperate function
1 parent 75e6a64 commit 9c627c6

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

helix-term/src/application.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -366,29 +366,39 @@ impl Application {
366366
self.editor.refresh_config();
367367
}
368368

369-
fn refresh_config(&mut self) {
370-
let config = Config::load_default().unwrap_or_else(|err| {
371-
self.editor.set_error(err.to_string());
372-
Config::default()
373-
});
374-
375-
// Refresh theme
369+
/// Refresh theme after config change
370+
fn refresh_theme(&mut self, config: &Config) {
376371
if let Some(theme) = config.theme.clone() {
377372
let true_color = self.true_color();
378-
self.editor.set_theme(
379-
self.theme_loader
380-
.load(&theme)
381-
.map_err(|e| {
382-
log::warn!("failed to load theme `{}` - {}", theme, e);
383-
e
384-
})
385-
.ok()
386-
.filter(|theme| (true_color || theme.is_16_color()))
387-
.unwrap_or_else(|| self.theme_loader.default_theme(true_color)),
388-
);
373+
match self.theme_loader.load(&theme) {
374+
Ok(theme) => {
375+
if true_color || theme.is_16_color() {
376+
self.editor.set_theme(theme);
377+
} else {
378+
self.editor
379+
.set_error("theme requires truecolor support, which is not available");
380+
}
381+
}
382+
Err(err) => {
383+
let err_string = format!("failed to load theme `{}` - {}", theme, err);
384+
self.editor.set_error(err_string);
385+
}
386+
}
389387
}
388+
}
390389

391-
self.config.store(Arc::new(config));
390+
fn refresh_config(&mut self) {
391+
match Config::load_default() {
392+
Ok(config) => {
393+
self.refresh_theme(&config);
394+
395+
// Store new config
396+
self.config.store(Arc::new(config));
397+
}
398+
Err(err) => {
399+
self.editor.set_error(err.to_string());
400+
}
401+
}
392402
}
393403

394404
fn true_color(&self) -> bool {

0 commit comments

Comments
 (0)