Skip to content

Improve error handling for config-reload #3668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,35 @@ impl Application {
}

fn refresh_config(&mut self) {
let config = Config::load_default().unwrap_or_else(|err| {
self.editor.set_error(err.to_string());
Config::default()
});
match Config::load_default() {
Ok(config) => {
// Refresh theme
if let Some(theme) = config.theme.clone() {
let true_color = self.true_color();
match self.theme_loader.load(&theme) {
Ok(theme) => {
if true_color || theme.is_16_color() {
self.editor.set_theme(theme);
} else {
self.editor.set_error(
"theme requires truecolor support, which is not available",
);
}
}
Err(err) => {
let err_string = format!("failed to load theme `{}` - {}", theme, err);
self.editor.set_error(err_string);
}
}
}

// Refresh theme
if let Some(theme) = config.theme.clone() {
let true_color = self.true_color();
self.editor.set_theme(
self.theme_loader
.load(&theme)
.map_err(|e| {
log::warn!("failed to load theme `{}` - {}", theme, e);
e
})
.ok()
.filter(|theme| (true_color || theme.is_16_color()))
.unwrap_or_else(|| self.theme_loader.default_theme(true_color)),
);
// Refresh config
self.config.store(Arc::new(config));
}
Err(err) => {
self.editor.set_error(err.to_string());
}
}

self.config.store(Arc::new(config));
}

fn true_color(&self) -> bool {
Expand Down