Skip to content

Commit e47dcdf

Browse files
committed
fix: crash on first run
Signed-off-by: Sam Gammon <[email protected]>
1 parent 64b06e3 commit e47dcdf

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/lib.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -515,25 +515,28 @@ impl Orogene {
515515
}) {
516516
let config_dir = config_path.parent().expect("must have parent");
517517
if !config_dir.exists() {
518-
std::fs::create_dir_all(config_dir).unwrap();
518+
std::fs::create_dir_all(config_dir).expect("failed to create config dir");
519519
}
520520
let mut config: KdlDocument = std::fs::read_to_string(&config_path)
521521
.unwrap_or_default()
522522
.parse()?;
523523

524-
// restore first-time as global config
525-
if let Some(opt) = config
526-
.get_mut("options")
527-
.unwrap()
528-
.children()
529-
.unwrap()
530-
.get("first-time")
531-
{
532-
if let Some(val) = opt.get(0) {
533-
// we've been here before; bail
534-
if !val.as_bool().unwrap_or(false) {
535-
self.first_time = false;
536-
return Ok(());
524+
// do we have a config file?
525+
if !config.is_empty() {
526+
// restore first-time as global config
527+
if let Some(opt) = config
528+
.get_mut("options")
529+
.expect("must have options")
530+
.children()
531+
.expect("options must have children")
532+
.get("first-time")
533+
{
534+
if let Some(val) = opt.get(0) {
535+
// we've been here before; bail
536+
if !val.as_bool().unwrap_or(false) {
537+
self.first_time = false;
538+
return Ok(());
539+
}
537540
}
538541
}
539542
}
@@ -544,7 +547,7 @@ impl Orogene {
544547

545548
let config_dir = config_path.parent().expect("must have parent");
546549
if !config_dir.exists() {
547-
std::fs::create_dir_all(config_dir).unwrap();
550+
std::fs::create_dir_all(config_dir).expect("failed to create config dir");
548551
}
549552
let telemetry_exists = config.query("options > telemetry")?.is_some();
550553
if config.get("options").is_none() {

0 commit comments

Comments
 (0)