🐛 fix(config): improve rule removal and logging
- fix the logic of `remove_rule_by_label` to check label existence correctly - change the error returned when label not found to include the label - add log information when removing rules by id or label
This commit is contained in:
committed by
Jeremiah Russell
parent
9e5b0a2cdd
commit
0dab9cc427
@@ -109,7 +109,7 @@ impl Config {
|
|||||||
/// Remove a rule by the ID specified
|
/// Remove a rule by the ID specified
|
||||||
pub fn remove_rule_by_id(&mut self, id: usize) -> crate::Result<()> {
|
pub fn remove_rule_by_id(&mut self, id: usize) -> crate::Result<()> {
|
||||||
self.rules.remove(&id.to_string());
|
self.rules.remove(&id.to_string());
|
||||||
|
log::info!("Rule `{id}` has been removed.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,8 +117,8 @@ impl Config {
|
|||||||
pub fn remove_rule_by_label(&mut self, label: &str) -> crate::Result<()> {
|
pub fn remove_rule_by_label(&mut self, label: &str) -> crate::Result<()> {
|
||||||
let labels = self.labels();
|
let labels = self.labels();
|
||||||
|
|
||||||
if labels.contains(&label.to_string()) {
|
if !labels.contains(&label.to_string()) {
|
||||||
return Err(Error::LabelNotFoundInRules);
|
return Err(Error::LabelNotFoundInRules(label.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let rule_id = self.find_label(label);
|
let rule_id = self.find_label(label);
|
||||||
@@ -128,6 +128,7 @@ impl Config {
|
|||||||
|
|
||||||
self.rules.remove(&rule_id.to_string());
|
self.rules.remove(&rule_id.to_string());
|
||||||
|
|
||||||
|
log::info!("Rule containing the label `{label}` has been removed.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user