Skip to main content

xbp_analysis/application/rules/
ignored_failure.rs

1use 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 IgnoredFailureRule;
10
11impl Rule for IgnoredFailureRule {
12    fn meta(&self) -> &RuleMeta {
13        static META: OnceLock<RuleMeta> = OnceLock::new();
14        META.get_or_init(|| RuleMeta {
15            id: "ignored-failure".into(),
16            name: "Ignored failure".into(),
17            description: "A fallible operation's error is discarded without handling.".into(),
18            default_severity: Severity::High,
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::IgnoredFailure)
26            .map(|(lang, c)| {
27                finding_from_concept(
28                    &self.meta().id,
29                    lang,
30                    c,
31                    Severity::High,
32                    Confidence::High,
33                    "Fallible result is ignored; failure becomes silent success.",
34                    "Upstream errors are dropped; callers assume success and corrupt state.",
35                    "Propagate with ? / map_err, or match and handle both arms explicitly.",
36                )
37            })
38            .collect()
39    }
40}