Skip to content

Commit

Permalink
feat(config): added logs at warn level if user config thresholds are …
Browse files Browse the repository at this point in the history
…invalid
  • Loading branch information
luisnquin committed Jan 28, 2024
1 parent f3c263c commit 31896b0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,17 @@ impl Config {
}

fn merge(mut self, other: Config) -> Config {
let warn_if_not_zero = |threshold: u8, label: &str| {
if threshold != 0 {
warn!(
"invalid {} threshold '{}', default will be used",
label, threshold
)
}
};

if self.reminder.threshold <= 0 || self.reminder.threshold > 100 {
warn_if_not_zero(self.reminder.threshold, "reminder");
self.reminder.threshold = other.reminder.threshold
}

Expand All @@ -108,6 +118,7 @@ impl Config {
}

if self.threat.threshold <= 0 || self.threat.threshold > 100 {
warn_if_not_zero(self.threat.threshold, "threat");
self.threat.threshold = other.threat.threshold
}

Expand All @@ -120,6 +131,7 @@ impl Config {
}

if self.warn.threshold <= 0 || self.warn.threshold > 100 {
warn_if_not_zero(self.warn.threshold, "warn");
self.warn.threshold = other.warn.threshold
}

Expand Down

0 comments on commit 31896b0

Please sign in to comment.