xbp_analysis/application/rules/
empty_handler.rs1use super::{base_caps, concepts_of, finding_from_concept};
2use crate::domain::concepts::ConceptKind;
3use crate::domain::model::LanguageModel;
4use crate::domain::rule::{Rule, RuleMeta};
5use crate::domain::types::{Confidence, Finding, Severity};
6use std::sync::OnceLock;
7
8#[derive(Default)]
9pub struct EmptyHandlerRule;
10
11impl Rule for EmptyHandlerRule {
12 fn meta(&self) -> &RuleMeta {
13 static META: OnceLock<RuleMeta> = OnceLock::new();
14 META.get_or_init(|| RuleMeta {
15 id: "empty-handler".into(),
16 name: "Empty error handler".into(),
17 description: "Error arm or catch block is empty.".into(),
18 default_severity: Severity::Medium,
19 required_capabilities: base_caps(),
20 autofix_safe: false,
21 })
22 }
23
24 fn evaluate(&self, model: &LanguageModel) -> Vec<Finding> {
25 concepts_of(model, ConceptKind::EmptyHandler)
26 .map(|(lang, c)| {
27 finding_from_concept(
28 &self.meta().id,
29 lang,
30 c,
31 Severity::Medium,
32 Confidence::High,
33 "Error handler is empty; failures are swallowed.",
34 "Silent failure hides outages and makes incident response impossible.",
35 "Log with context, return an error, or implement real recovery.",
36 )
37 })
38 .collect()
39 }
40}