Skip to content

fix(critcheck): treat BSD grep regex errors as malformed checks - #194

Closed
pcbeingused333 wants to merge 1 commit into
Agent-Field:mainfrom
pcbeingused333:fix/bsd-grep-regex-errors
Closed

pcbeingused333 wants to merge 1 commit into
Agent-Field:mainfrom
pcbeingused333:fix/bsd-grep-regex-errors

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #192
Fixes #190

Summary

  • Malformed recognized GNU grep and ripgrep regex failures (Unmatched, Invalid regular expression, Trailing backslash, regex parse error) and option errors. It did not recognise BSD grep.
  • macOS ships BSD grep. The same refusal comes from regerror(3) in lowercase: parentheses not balanced, brackets ([ ]) not balanced, trailing backslash (\), and the other pattern-compile errors (braces not balanced, invalid regular expression, invalid character class, invalid character range, invalid backreference number, invalid repetition count(s), invalid collating element, repetition-operator operand invalid, empty (sub)expression).
  • A criterion such as grep -E 'Checksum(' file therefore stayed a real failure on macOS, and TestAMalformedCheckWithNoRepairIsNotCounted failed there because it re-runs grep. Those lines are now usage errors, same as the GNU wording. A missing file (No such file or directory) and out of memory stay real failures. Exit status 2 alone is not enough: grep uses it for both.

Testing and validation

  • TestMalformedTellsUsageFromAssertion covers each BSD regerror line above, plus egrep:, and keeps a missing file and out of memory as assertions.
  • TestABSDGrepRegexErrorIsNotCounted re-runs `grep -E 'Checksum(' ledger.go` with tool output grep: parentheses not balanced and expects the criterion not counted.
  • TestAMissingGrepTargetStaysARealFailure keeps grep: ledger.go: No such file or directory as a failure.
  • Before the signature change, TestABSDGrepRegexErrorIsNotCounted and TestMalformedTellsUsageFromAssertion failed. After it, go test -race -count=1 ./internal/critcheck passed (23 tests). The existing GNU case still passes on a host whose grep prints Unmatched (.

Behavior Impact

  • Backward compatible behavior change

A malformed grep or egrep pattern is not counted on macOS as well as on Linux. A check that runs and fails, including a missing path, is unchanged.

AI assistance was used to prepare this change and its tests.

macOS grep reports "parentheses not balanced" and a lowercase
"trailing backslash" when it refuses a pattern. Those lines were
not usage errors, so a malformed grep criterion counted as a
real failure.

Fixes Agent-Field#192
Fixes Agent-Field#190
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@AbirAbbas

Copy link
Copy Markdown
Collaborator

Thanks for the contribution. The CLA is still unsigned after the reminder from the CLA bot, so we are closing this for now. Please reopen it once the CLA is signed and we will take another look.

@AbirAbbas AbirAbbas closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants