Skip to content

Commit

Permalink
cli: when config is invalid, use default config
Browse files Browse the repository at this point in the history
When we fail to read the user's config, it seems obviously better to
use the default config than to not use it. It doesn't matter yet, but
it will matter when I've moved color configs out of `formatter.rs` and
into a `.toml` file. Without this change, we'd lose the default
coloring of the error message for config errors.
  • Loading branch information
martinvonz committed Dec 24, 2022
1 parent 462f696 commit 6514ab2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use chrono::DateTime;

use crate::backend::{Signature, Timestamp};

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
pub struct UserSettings {
config: config::Config,
timestamp: Option<Timestamp>,
Expand Down
2 changes: 1 addition & 1 deletion src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ pub fn create_ui() -> (Ui, Result<(), CommandError>) {
match read_config() {
Ok(user_settings) => (Ui::for_terminal(user_settings), Ok(())),
Err(err) => {
let ui = Ui::for_terminal(UserSettings::default());
let ui = Ui::for_terminal(UserSettings::from_config(crate::config::default_config()));
(ui, Err(CommandError::ConfigError(err.to_string())))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn env_base() -> config::Config {
builder.build().unwrap()
}

fn default_config() -> config::Config {
pub fn default_config() -> config::Config {
// Syntax error in default config isn't a user error. That's why defaults are
// loaded by separate builder.
config::Config::builder()
Expand Down

0 comments on commit 6514ab2

Please sign in to comment.