{"record":{"id":"dec066cd44e1aab5","repo":"nikivdev/code","slug":"invariant-violations-found-mode-block-findin","errorCode":null,"errorMessage":"Invariant violations found (mode=block): {} finding(s)","messagePattern":"Invariant violations found \\(mode=block\\): (.+?) finding\\(s\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/invariants.rs","lineNumber":88,"sourceCode":"            check_deps(root, &changed_files, &deps_config.approved, &mut findings);\n        }\n    }\n\n    // 3. File size limits.\n    if let Some(files_config) = &inv.files {\n        if let Some(max_lines) = files_config.max_lines {\n            check_file_sizes(root, &changed_files, max_lines, &mut findings);\n        }\n    }\n\n    // Print results.\n    print_report(&inv, &findings);\n\n    let has_blocking = findings\n        .iter()\n        .any(|f| f.severity == \"critical\" || f.severity == \"warning\");\n    if mode == \"block\" && has_blocking {\n        anyhow::bail!(\n            \"Invariant violations found (mode=block): {} finding(s)\",\n            findings.len()\n        );\n    }\n\n    Ok(Report {\n        findings,\n        invariants_loaded: true,\n        mode,\n    })\n}\n\nfn check_forbidden_patterns(inv: &InvariantsConfig, diff: &str, findings: &mut Vec<Finding>) {\n    // Skip flow.toml itself — it contains the forbidden list definitions.\n    let skip_files = [\"flow.toml\"];\n\n    for pattern in &inv.forbidden {\n        let pat_lower = pattern.to_lowercase();","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/invariants.rs#L70-L106","documentation":"The invariants check function evaluates configured invariant checks, prints a report, and if mode is 'block' and any finding has severity 'critical' or 'warning', it aborts the run with this error summarizing the finding count. It is the library's deliberate fail-closed gate, not an unexpected fault.","triggerScenarios":"Running check with mode=\"block\" and at least one finding whose severity is \"critical\" or \"warning\". 'info'-severity findings do not block.","commonSituations":"CI pipelines enforcing repo invariants on PRs; local pre-commit hooks with mode=block; after adding new invariant rules that existing code violates; environment drift producing warnings that were previously absent.","solutions":["Read the printed report above the error to see which invariants failed and fix the flagged code/config","Run with a non-block mode (e.g. report/warn) to unblock while triaging","Downgrade the finding severity in the invariant configuration if the rule is too strict","Fix or waive (allowlist) the specific findings in your invariant config"],"exampleFix":"// before (blocks CI)\ncheck(mode = \"block\")  // Invariant violations found (mode=block): 3 finding(s)\n// after (triage first)\ncheck(mode = \"report\")  // prints findings without failing, then fix them","handlingStrategy":"try-catch","validationCode":"// run a report-only check before the blocking one\nlet report = check(mode = \"report\")?;\nif report.findings.iter().any(|f| f.severity == \"critical\" || f.severity == \"warning\") {\n    eprintln!(\"Blocking findings present; fix before running mode=block\");\n}","typeGuard":null,"tryCatchPattern":"match check(mode = \"block\") {\n    Err(e) if e.to_string().starts_with(\"Invariant violations found\") => {\n        eprintln!(\"{} — see the printed report for details\", e);\n        std::process::exit(1); // enforce gate in CI\n    }\n    other => other?,\n}","preventionTips":["Run invariant checks in report mode locally before CI blocks the PR","Keep invariant rules and allowlists updated as the codebase evolves","Fix or explicitly waive critical/warning findings promptly","Distinguish severity levels in tooling so info findings never block"],"tags":["invariants","ci","policy-violation"],"backgroundTag":"invariant-violation-block","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}