fix(regexpool): preserve regex compilation errors - #7324
Conversation
✅ Deploy Preview for pipecd-site canceled.
|
529f672 to
40cfcd6
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The updated test currently asserts the full stdlib regex error string, which is brittle across Go versions and should be relaxed to stable substring checks.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves pkg/regexpool error reporting by preserving and returning the underlying regexp.Compile compilation error (including for cached failed expressions), which makes invalid regex patterns significantly easier to diagnose.
Changes:
- Cache compilation failures as
map[string]error(instead ofstruct{}) so the original error is retained. - Wrap returned errors with
%wand include the expression via%qfor clearer diagnostics. - Update tests to validate the improved error output on first and subsequent (cached) failures.
File summaries
| File | Description |
|---|---|
| pkg/regexpool/regexpool.go | Store per-expression compile errors and wrap them when returning failures (including cached failures). |
| pkg/regexpool/regexpool_test.go | Adjust tests to check the improved error message behavior for initial and repeated invalid expressions. |
Review details
Suppressed comments (1)
pkg/regexpool/regexpool_test.go:43
- Same as above: asserting the full
regexp.Compileerror text is brittle. Use substring assertions so the test keeps validating the improved diagnostics without depending on exact stdlib wording/punctuation.
regex, err = pool.Get("(abc")
assert.EqualError(t, err, "unable to compile \"(abc\": error parsing regexp: missing closing ): `(abc`")
assert.Nil(t, regex)
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Anubhav Singh <anmolkfzd@gmail.com>
40cfcd6 to
809180d
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The change is small, localized, and the updated tests cover both the initial failure and cached-failure behavior with the new wrapped error diagnostics.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
What this PR does:
This PR preserves and returns the underlying regular expression compilation error in
pkg/regexpool.Previously, when a regular expression failed to compile,
Pool.Getreturned only the expression:unable to compile: (abcThe actual error returned by
regexp.Compilewas discarded.This change stores the compilation error for failed expressions and wraps it when returning the error:
unable to compile "(abc": error parsing regexp: missing closing )The cached failure path now also returns the original compilation error instead of losing that diagnostic information.
Tests were updated to verify the improved error message for both the initial failed compilation and subsequent requests for the same invalid expression.
Why we need it:
Discarding the underlying compilation error makes invalid regular expressions harder to diagnose.
Preserving the error from
regexp.Compileprovides useful information about why compilation failed while maintaining the existing behavior of caching failed expressions to avoid repeatedly compiling the same invalid expression.Does this PR introduce a user-facing change?:
Yes, error diagnostics are improved.
Screenshots/Videos (for documentation or website changes):
N/A. This PR does not modify documentation, website, or Markdown files.