ci: enforce no panics in production code#1087
Conversation
Add a diff-based CI job and pre-commit hook check that block panic-inducing calls (.unwrap(), .expect(), assert!, assert_eq!, assert_ne!) from entering production Rust code. debug_assert is excluded (compiled out in release). False positives can be suppressed with an inline `// safety: <reason>` comment. - pre-commit-safety.sh: add check 6 (PANIC) for staged diffs - code_style.yml: add `no-panics` job, wire into roll-up gate - check-boundaries.sh: extend check 2 to also catch assert!() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
zmanian
left a comment
There was a problem hiding this comment.
This PR targets main but appears to be branched from staging, pulling in all staging commits (54 commits, diff too large for GitHub to render).
Should this target staging instead? The actual new content seems to be just the no-panics CI job, pre-commit hook check, and check-boundaries.sh update. Targeting staging would make this much easier to review.
zmanian
left a comment
There was a problem hiding this comment.
Clean and well-scoped. Three changes that all serve the same purpose:
-
CI job (
no-panics): Diffs against base SHA, catches.unwrap(),.expect(),assert!()insrc/andcrates/added lines. Properly excludesdebug_assert, test annotations, and// safety:suppressions. Wired into thecode-styleroll-up gate. -
check-boundaries.sh: Extends Check 2 to also catch
assert!()variants with the same exclusions. -
pre-commit-safety.sh: Adds Check 6 matching the same patterns in staged diffs.
The // safety: <reason> escape hatch is the right approach for legitimate uses (e.g., after infallible operations). The grep patterns correctly use [^_]assert to avoid matching debug_assert.
One minor note: the CI job's grep filters on added lines (^\+[^+]) then excludes lines containing #[test] or mod tests. This works for inline test annotations but won't catch if a .unwrap() is added inside a #[cfg(test)] mod tests { ... } block where the mod tests line itself wasn't in the diff. In practice this is fine since the pre-existing test module boundary won't appear in the diff -- only new unwraps will, and those in test functions will have #[test] nearby. Non-blocking.
LGTM
…1087) Add a diff-based CI job and pre-commit hook check that block panic-inducing calls (.unwrap(), .expect(), assert!, assert_eq!, assert_ne!) from entering production Rust code. debug_assert is excluded (compiled out in release). False positives can be suppressed with an inline `// safety: <reason>` comment. - pre-commit-safety.sh: add check 6 (PANIC) for staged diffs - code_style.yml: add `no-panics` job, wire into roll-up gate - check-boundaries.sh: extend check 2 to also catch assert!() Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
…earai#1087) Add a diff-based CI job and pre-commit hook check that block panic-inducing calls (.unwrap(), .expect(), assert!, assert_eq!, assert_ne!) from entering production Rust code. debug_assert is excluded (compiled out in release). False positives can be suppressed with an inline `// safety: <reason>` comment. - pre-commit-safety.sh: add check 6 (PANIC) for staged diffs - code_style.yml: add `no-panics` job, wire into roll-up gate - check-boundaries.sh: extend check 2 to also catch assert!() Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
…earai#1087) Add a diff-based CI job and pre-commit hook check that block panic-inducing calls (.unwrap(), .expect(), assert!, assert_eq!, assert_ne!) from entering production Rust code. debug_assert is excluded (compiled out in release). False positives can be suppressed with an inline `// safety: <reason>` comment. - pre-commit-safety.sh: add check 6 (PANIC) for staged diffs - code_style.yml: add `no-panics` job, wire into roll-up gate - check-boundaries.sh: extend check 2 to also catch assert!() Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
no-panicsCI job tocode_style.ymlthat diffs the PR against the base branch and blocks.unwrap(),.expect(),assert!(),assert_eq!(),assert_ne!()insrc/andcrates/production codepre-commit-safety.shcatching the same patterns in staged diffsassert!()variantsAll checks exclude
debug_assert(compiled out in release), test annotations (#[cfg(test)],#[test],mod tests), and lines with// safety: <reason>suppression comments.Test plan
no-panicsjob passes on this PR (no production panic calls in the diff).unwrap()in non-test code and confirm it blocks// safety: <reason>suppression works for legitimate usesbash scripts/check-boundaries.shand verify Check 2 now reportsassert!()calls🤖 Generated with Claude Code