nikivdev/code · error

Invariant violations found (mode=block): {} finding(s)

Error message

Invariant violations found (mode=block): {} finding(s)

What it means

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.

Source

Thrown at src/invariants.rs:88

            check_deps(root, &changed_files, &deps_config.approved, &mut findings);
        }
    }

    // 3. File size limits.
    if let Some(files_config) = &inv.files {
        if let Some(max_lines) = files_config.max_lines {
            check_file_sizes(root, &changed_files, max_lines, &mut findings);
        }
    }

    // Print results.
    print_report(&inv, &findings);

    let has_blocking = findings
        .iter()
        .any(|f| f.severity == "critical" || f.severity == "warning");
    if mode == "block" && has_blocking {
        anyhow::bail!(
            "Invariant violations found (mode=block): {} finding(s)",
            findings.len()
        );
    }

    Ok(Report {
        findings,
        invariants_loaded: true,
        mode,
    })
}

fn check_forbidden_patterns(inv: &InvariantsConfig, diff: &str, findings: &mut Vec<Finding>) {
    // Skip flow.toml itself — it contains the forbidden list definitions.
    let skip_files = ["flow.toml"];

    for pattern in &inv.forbidden {
        let pat_lower = pattern.to_lowercase();

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read the printed report above the error to see which invariants failed and fix the flagged code/config
  2. Run with a non-block mode (e.g. report/warn) to unblock while triaging
  3. Downgrade the finding severity in the invariant configuration if the rule is too strict
  4. Fix or waive (allowlist) the specific findings in your invariant config

Example fix

// before (blocks CI)
check(mode = "block")  // Invariant violations found (mode=block): 3 finding(s)
// after (triage first)
check(mode = "report")  // prints findings without failing, then fix them
Defensive patterns

Strategy: try-catch

Validate before calling

// run a report-only check before the blocking one
let report = check(mode = "report")?;
if report.findings.iter().any(|f| f.severity == "critical" || f.severity == "warning") {
    eprintln!("Blocking findings present; fix before running mode=block");
}

Try / catch

match check(mode = "block") {
    Err(e) if e.to_string().starts_with("Invariant violations found") => {
        eprintln!("{} — see the printed report for details", e);
        std::process::exit(1); // enforce gate in CI
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running check with mode="block" and at least one finding whose severity is "critical" or "warning". 'info'-severity findings do not block.

Common situations: 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.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/dec066cd44e1aab5. Report an issue: GitHub.