xbp-analysis 10.57.0

Language-agnostic static analysis (error-handling / Aspirator-style) for XBP
Documentation
use super::{base_caps, concepts_of, finding_from_concept};
use crate::domain::concepts::ConceptKind;
use crate::domain::model::LanguageModel;
use crate::domain::rule::{Rule, RuleMeta};
use crate::domain::types::{Confidence, Finding, Severity};
use std::sync::OnceLock;

#[derive(Default)]
pub struct EmptyHandlerRule;

impl Rule for EmptyHandlerRule {
    fn meta(&self) -> &RuleMeta {
        static META: OnceLock<RuleMeta> = OnceLock::new();
        META.get_or_init(|| RuleMeta {
            id: "empty-handler".into(),
            name: "Empty error handler".into(),
            description: "Error arm or catch block is empty.".into(),
            default_severity: Severity::Medium,
            required_capabilities: base_caps(),
            autofix_safe: false,
        })
    }

    fn evaluate(&self, model: &LanguageModel) -> Vec<Finding> {
        concepts_of(model, ConceptKind::EmptyHandler)
            .map(|(lang, c)| {
                finding_from_concept(
                    &self.meta().id,
                    lang,
                    c,
                    Severity::Medium,
                    Confidence::High,
                    "Error handler is empty; failures are swallowed.",
                    "Silent failure hides outages and makes incident response impossible.",
                    "Log with context, return an error, or implement real recovery.",
                )
            })
            .collect()
    }
}