Skip to content

Commit 7478737

Browse files
authored
CLI - Exit when config is malformed (#1669)
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent caaafa4 commit 7478737

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

crates/cli/src/config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,17 +790,16 @@ impl Config {
790790
Ok(toml::from_str(&text)?)
791791
}
792792

793-
pub fn load() -> Self {
793+
pub fn load() -> anyhow::Result<Self> {
794794
let home_path = Self::system_config_path();
795795
let home = if home_path.exists() {
796796
Self::load_from_file(&home_path)
797-
.inspect_err(|e| eprintln!("config file {home_path:?} is invalid: {e:#?}"))
798-
.unwrap_or_default()
797+
.inspect_err(|e| eprintln!("config file {home_path:?} is invalid: {e:#?}"))?
799798
} else {
800799
RawConfig::new_with_localhost()
801800
};
802801

803-
Self { home }
802+
Ok(Self { home })
804803
}
805804

806805
#[doc(hidden)]

crates/cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async fn main() -> Result<(), anyhow::Error> {
1313
let matches = get_command().get_matches();
1414
let (cmd, subcommand_args) = matches.subcommand().unwrap();
1515

16-
let config = Config::load();
16+
let config = Config::load()?;
1717
// Save a default version to disk
1818
config.save();
1919

0 commit comments

Comments
 (0)