{"record":{"id":"0524103302711102","repo":"nikivdev/code","slug":"commit-blocked-by-invariant-gate-finding-s","errorCode":null,"errorMessage":"Commit blocked by invariant gate ({} finding(s))","messagePattern":"Commit blocked by invariant gate \\((.+?) finding\\(s\\)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":3388,"sourceCode":"        .iter()\n        .any(|f| f.severity == \"critical\" || f.severity == \"warning\");\n\n    // Print findings.\n    if !findings.is_empty() {\n        eprintln!();\n        eprintln!(\"  invariants: {} finding(s)\", findings.len());\n        for f in &findings {\n            let loc = f.file.as_deref().unwrap_or(\"(diff)\");\n            eprintln!(\n                \"    [{}:{}] {} — {}\",\n                f.severity, f.category, loc, f.message\n            );\n        }\n    }\n\n    let pass = !has_blocking;\n    if !pass && mode == \"block\" {\n        bail!(\n            \"Commit blocked by invariant gate ({} finding(s))\",\n            findings.len()\n        );\n    }\n    if !pass {\n        eprintln!(\"  invariants: warning only (mode=warn)\");\n    }\n\n    Ok(InvariantGateReport { findings })\n}\n\n/// Check a package.json for dependencies not on the approved list.\nfn check_unapproved_deps(\n    package_json: &str,\n    approved: &[String],\n    file_path: &str,\n    findings: &mut Vec<InvariantFinding>,\n) {","sourceCodeStart":3370,"sourceCodeEnd":3406,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L3370-L3406","documentation":"The invariant gate evaluates a list of findings against project invariants before commit. If any finding is blocking (has_blocking) and the gate mode is \"block\", the commit is aborted with the total finding count in the message; in \"warn\" mode it only prints a warning. It encodes team-defined invariants as hard commit prerequisites.","triggerScenarios":"Committing when the invariant runner produced findings (e.g. forbidden patterns, missing markers, structural violations) and mode == \"block\"; the message interpolates findings.len().","commonSituations":"Introducing code that violates repo invariants (disallowed APIs, missing tests tags, oversized functions); newly added invariants flagging pre-existing code; stale config after invariant rule updates.","solutions":["Read the printed invariant findings and fix each violating spot in your changes.","Re-run the invariant check locally (if exposed) until it reports zero findings, then commit.","If a finding is a false positive, update or scope the invariant rule in config.","Switch mode to \"warn\" only with team approval; do not bypass shared policy."],"exampleFix":"// before: invariant forbids unwrap() in src/\nlet v = config.get(\"k\").unwrap();\n// after\nlet v = config.get(\"k\").context(\"missing key k\")?;","handlingStrategy":"validation","validationCode":"// Run the invariant check (if exposed) before committing and require zero blocking findings\nlet findings = run_invariant_check()?;\nlet has_blocking = findings.iter().any(|f| f.is_blocking);\nif has_blocking {\n    eprintln!(\"fix {} blocking invariant finding(s) before committing\", findings.len());\n}","typeGuard":null,"tryCatchPattern":"match commit_flow() {\n    Err(e) if e.to_string().starts_with(\"Commit blocked by invariant gate\") => {\n        eprintln!(\"address each printed invariant finding, then re-commit\");\n    }\n    other => other?,\n}","preventionTips":["Run invariant checks locally as part of your pre-commit routine.","Keep invariant rules documented so new code avoids known violations.","When adding invariants, sweep the codebase first to avoid flagging existing code."],"tags":["git","pre-commit","invariants","policy-gate"],"backgroundTag":"commit-blocked-by-gate","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}