Skip to content

Fix embedded error-code detection in thrown-error rule - #52972

Merged
pelikhan merged 4 commits into
mainfrom
copilot/eslint-factory-fix-error-code-matching
Aug 15, 2026
Merged

Fix embedded error-code detection in thrown-error rule#52972
pelikhan merged 4 commits into
mainfrom
copilot/eslint-factory-fix-error-code-matching

Conversation

Copilot AI commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

require-error-code-in-thrown-error missed valid error-code constants when embedded after underscores, such as SAFE_OUTPUT_E099. This caused false positives in setup action scripts using SAFE_OUTPUT-style codes.

  • Matcher
    • Recognize ERR_* and E### segments after identifier separators.
    • Preserve boundaries to reject partial matches such as SAFE_OUTPUT_E099X.
throw new Error(`${SAFE_OUTPUT_E099}: Failed to fetch review`);
throw new Error(`${MY_PREFIX_ERR_CONFIG}: Invalid configuration`);
  • Regression coverage
    • Add valid template-literal cases for embedded numeric and named codes.
    • Add invalid cases for missing, extended, and embedded non-code tokens.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 18.4 AIC · ⌖ 6.84 AIC · ⊞ 8.7K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 15, 2026 21:52
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix false positives in require-error-code-in-thrown-error rule Fix embedded error-code detection in thrown-error rule Aug 15, 2026
Copilot AI requested a review from pelikhan August 15, 2026 21:57
@pelikhan
pelikhan marked this pull request as ready for review August 15, 2026 21:59
Copilot AI balanced review requested due to automatic review settings August 15, 2026 21:59
@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #52972 does not have the 'implementation' label and has 0 new lines of code in business logic directories (2 files changed, none in src/, lib/, pkg/, internal/, app/, core/, domain/, services/, or api/).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship. Diff is a minimal regex fix (one-line change) plus targeted regression tests; no over-engineering, dead code, or speculative abstraction to cut.

Generated by Ponytail Reviewer for #52972

@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-15T00:00:00Z
review_event: COMMENT
top_themes:
  - regex boundary fix looks correct
  - regression coverage added for embedded identifiers
  - no blocking issues found
files_reviewed:
  - eslint-factory/src/rules/require-error-code-in-thrown-error.ts
  - eslint-factory/src/rules/require-error-code-in-thrown-error.test.ts
comment_count: 0

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 2.9 AIC · ⌖ 6.45 AIC · ⊞ 6.9K ·
Comment /review to run again

@github-actions github-actions Bot 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.

Verdict

Non-blocking: the regex boundary change and accompanying regression cases look internally consistent, and I did not find a changed-line correctness or maintainability issue worth blocking this PR over.

Highlights
  • The new negative-lookbehind still rejects partial suffix matches like SAFE_OUTPUT_E099X and ERR_CONFIGmore.
  • The added tests cover both embedded numeric codes and embedded ERR_ segments, plus several nearby false-positive/false-negative cases.
  • I did not find a missed changed-line edge case in the updated matcher logic.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 2.9 AIC · ⌖ 6.45 AIC · ⊞ 6.9K
Comment /review to run again

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.

Pull request overview

Updates the ESLint rule to recognize error-code segments embedded after underscores without accepting partial matches.

Changes:

  • Refines error-code boundary matching.
  • Adds regression tests for valid embedded codes and invalid lookalikes.
Show a summary per file
File Description
eslint-factory/src/rules/require-error-code-in-thrown-error.ts Updates error-code detection boundaries.
eslint-factory/src/rules/require-error-code-in-thrown-error.test.ts Adds embedded-code regression coverage.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions github-actions Bot mentioned this pull request Aug 15, 2026

@github-actions github-actions Bot 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.

The regex fix is correct and well-tested.

Root cause: The old pattern \bERR_[A-Z_]+\b used \b word boundaries. Since _ is a word character, the boundary before ERR_ is not triggered when preceded by _ (e.g. MY_PREFIX_ERR_CONFIG). This made the rule miss valid error codes embedded after underscored prefixes.

Fix: The new pattern replaces \b with a negative lookbehind (?<![A-Za-z0-9]), anchoring only on alphanumeric characters. This correctly matches MY_PREFIX_ERR_CONFIG and SAFE_OUTPUT_E099 while still rejecting FOOERR_CONFIG, MY_PREFIX_ERROR_CONFIG, and other non-error-code names.

All new valid and invalid test cases are well-chosen and cover the key boundary conditions.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 21.2 AIC · ⌖ 7.98 AIC · ⊞ 5.6K

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — changes look correct, one minor comment suggestion.

📋 Key Themes & Highlights

Key Themes

  • Correct root cause fix: Replacing \b with (?<![A-Za-z0-9]) so underscore serves as a valid separator is the right call — \b treats _ as a word character, which is why SAFE_OUTPUT_E099 failed to match.
  • Good regression tests: Valid cases for SAFE_OUTPUT_E099 and MY_PREFIX_ERR_CONFIG plus invalid boundary cases (E099X, FOOERR_CONFIG, ERR_CONFIGmore) cover the interesting edges well.

One Minor Point

  • The non-obvious choice of [A-Za-z0-9] over \b deserves a short inline comment to prevent a future simplification regressing the fix.

Positive Highlights

  • ✅ Minimal, surgical change — 1 line of production code
  • ✅ Regression tests added alongside the fix, matching /tdd red-green-refactor
  • ✅ Both ERR_* and E### patterns updated symmetrically in the regex

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 31.7 AIC · ⌖ 8.51 AIC · ⊞ 7.7K
Comment /matt to run again

const createRule = ESLintUtils.RuleCreator(name => `https://github.com/github/gh-aw/tree/main/eslint-factory#${name}`);

const ERROR_CODE_PATTERN = /\bERR_[A-Z_]+\b|\bE[0-9]{3}\b/;
const ERROR_CODE_PATTERN = /(?<![A-Za-z0-9])ERR_[A-Z_]+\b|(?<![A-Za-z0-9])E[0-9]{3}\b/;

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.

[/diagnosing-bugs] The lookbehind uses [A-Za-z0-9] (not \b) to intentionally treat _ as a separator, enabling SAFE_OUTPUT_ERR_CONFIG to match while blocking FOOERR_CONFIG. Without a comment, a future maintainer may simplify this back to \b and re-introduce the bug.

💡 Suggested comment
// Use [A-Za-z0-9] — not \b — so underscore acts as a word separator.
// This lets SAFE_OUTPUT_ERR_CONFIG match while rejecting FOOERR_CONFIG.
const ERROR_CODE_PATTERN = /(?<![A-Za-z0-9])ERR_[A-Z_]+\b|(?<![A-Za-z0-9])E[0-9]{3}\b/;

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Summary

Test Quality Score: 92/100Excellent

This PR adds 6 comprehensive test cases to validate the regex fix in the ESLint error-code detection rule. All tests directly validate the behavioral contract (pattern matching) with strong edge case coverage.


Test Analysis

Changed Files

File Type Changes
eslint-factory/src/rules/require-error-code-in-thrown-error.ts Source 1 line (regex fix with negative lookbehind)
eslint-factory/src/rules/require-error-code-in-thrown-error.test.ts Test 18 lines added (6 test cases)

Test Cases Added

Valid Pattern Cases (2 tests)
Test Pattern Why It Matters
SAFE_OUTPUT_E099 Numeric 3-digit code in template Ensures numeric E[0-9]{3} pattern works
MY_PREFIX_ERR_CONFIG Custom-prefixed error constant Allows flexible naming conventions (e.g., PREFIX_ERR_*)

Classification: design_test, high_value — both validate the extended pattern range needed for real-world error codes.

Invalid Pattern Cases (4 tests) — Edge Cases for Negative Lookbehind
Test Invalid Code Pattern Violation Why It Matters
MY_PREFIX_ERROR_CONFIG Uses ERROR_ not ERR_ Wrong prefix pattern Confirms only ERR_ and E[0-9]{3} are valid
SAFE_OUTPUT_E099X Uses E099X (4 digits) Numeric pattern boundary Validates 3-digit constraint (E[0-9]{3})
ERR_CONFIGmore ERR_CONFIG + trailing text Negative lookbehind (char after) Core fix validation: ensures alphanumeric cannot follow the pattern
FOOERR_CONFIG Prefix + ERR_CONFIG Negative lookbehind (char before) Core fix validation: ensures alphanumeric cannot precede the pattern

Classification: design_test, high_value — the last two directly validate the negative lookbehind assertion fix ((?<![A-Za-z0-9])), which is the core improvement in this PR.


Quality Metrics

Metric Result Notes
Design Tests 100% (6/6) All cases validate pattern-matching contracts
Edge Case Credit 83% (5/6) Strong negative lookbehind boundary coverage
Duplication 0 Each case is a distinct pattern variant
Test Inflation 18:1 High but acceptable; ESLint rule tests use inline test data in RuleTester
Assertions ✅ Strong Framework-based validation via ESLint RuleTester
Hard Violations None No mock libraries, no build-tag issues

Scoring Details

score = ((design_tests / total) * 40) +
        ((edge_tests / total) * 30) +
        (20 - duplicates * 5) +
        (inflation_ok ? 10 : 0)
      = (100% * 40) + (83% * 30) + 20 + 10 - 3
      = 92/100

Excellent threshold: ≥80 ✅


Recommendations

All checks passed. The tests comprehensively validate the regex pattern fix with clear edge case scenarios. No changes needed.

Why this is high quality:

  • Tests target design invariants (what patterns are/aren't valid)
  • Tests validate the actual fix (negative lookbehind assertions)
  • Edge cases cover pattern boundaries and constraints
  • Follows standard ESLint testing patterns (RuleTester inline cases)
  • Zero duplication or mock anti-patterns

🧪 Test quality analysis by Test Quality Sentinel · haiku45 · 23.1 AIC · ⌖ 3.59 AIC · ⊞ 7.9K ·
Comment /review to run again

@github-actions github-actions Bot 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.

✅ Test Quality Sentinel: 92/100 Excellent. 100% design tests validating the regex pattern fix with comprehensive edge case coverage for negative lookbehind assertions. No hard violations. 0% implementation tests (threshold: 30%).

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Quick triage for maintainer-ready follow-up:

Please refresh the branch if needed, address the remaining maintainer-facing follow-up, and run the pr-finisher skill before handing this PR back to maintainers.

Outstanding review items (newest first):

Failed checks from the compact candidate set:

  • None listed.

Branch update was requested automatically for this run when GitHub allows it.
Run context: https://github.com/github/gh-aw/actions/runs/31911601861

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 18.4 AIC · ⌖ 6.84 AIC · ⊞ 8.7K ·
Comment /souschef to run again

@pelikhan
pelikhan merged commit c563f57 into main Aug 15, 2026
1 check failed
@pelikhan
pelikhan deleted the copilot/eslint-factory-fix-error-code-matching branch August 15, 2026 22:29
Copilot stopped work on behalf of gh-aw-bot due to an error August 15, 2026 22:29
Copilot AI requested a review from gh-aw-bot August 15, 2026 22:29
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.87.0

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eslint-factory: require-error-code-in-thrown-error false-positives on error-code identifiers embedded after an underscore

4 participants