Skip to content

fix(regexpool): preserve regex compilation errors - #7324

Open
anubhavsingh2106 wants to merge 1 commit into
pipe-cd:masterfrom
anubhavsingh2106:fix/regexpool-compilation-errors
Open

fix(regexpool): preserve regex compilation errors#7324
anubhavsingh2106 wants to merge 1 commit into
pipe-cd:masterfrom
anubhavsingh2106:fix/regexpool-compilation-errors

Conversation

@anubhavsingh2106

Copy link
Copy Markdown
Contributor

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.Get returned only the expression:

unable to compile: (abc

The actual error returned by regexp.Compile was 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.Compile provides 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.

  • How are users affected by this change: Users receive the underlying regular expression compilation error, making invalid expressions easier to diagnose.
  • Is this breaking change: No.
  • How to migrate (if breaking change): N/A.

Screenshots/Videos (for documentation or website changes):

N/A. This PR does not modify documentation, website, or Markdown files.

Copilot AI lite review requested due to automatic review settings September 5, 2026 21:41
@anubhavsingh2106
anubhavsingh2106 requested a review from a team as a code owner September 5, 2026 21:41
@netlify

netlify Bot commented Sep 5, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 809180d
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a9d551f6edcd30007f6d972

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 of struct{}) so the original error is retained.
  • Wrap returned errors with %w and include the expression via %q for 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.Compile error 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.

Comment thread pkg/regexpool/regexpool_test.go
Comment thread pkg/regexpool/regexpool.go
Signed-off-by: Anubhav Singh <anmolkfzd@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants