Skip to content

Fix errorfwrapv false positive on explicit arg index before dynamic * width - #51932

Merged
pelikhan merged 4 commits into
mainfrom
copilot/errorfwrapv-fix-argument-index-bug
Aug 11, 2026
Merged

Fix errorfwrapv false positive on explicit arg index before dynamic * width#51932
pelikhan merged 4 commits into
mainfrom
copilot/errorfwrapv-fix-argument-index-bug

Conversation

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

parseFormatVerbs consumed an explicit [n] index immediately after % and marked it as the verb's value argument, before knowing whether that index actually feeds a following * width/precision. For %[1]*w, the index is re-consumed as the width source but valueArgIdx stays pointed at the width argument, so the real error argument ends up with no verb recorded and gets flagged as missing %w — on code that already wraps correctly.

func WrapWithWidth(width int, err error) error {
	return fmt.Errorf("%[1]*w", width, err) // flagged: "passes an error argument without %w"
}

Changes

  • pkg/linters/errorfwrapv/errorfwrapv.go: removed the speculative index parse before flag/width handling. The existing check after consumeFormatWidthOrPrecision already covers the "index directly before verb" case (it leaves i unchanged when there is no */width), so an index is now only attributed to the value argument once it's known not to feed a *.
  • pkg/linters/errorfwrapv/testdata/.../errorfwrapv.go: added GoodIndexedDynamicWidthWrap exercising fmt.Errorf("%[1]*w", width, err) with no expected diagnostic. Existing GoodIndexedWidthWrap (%[2]*[1]w) and BadIndexedWidthNoW (%[2]*[1]s) are unchanged.
  • scripts/agent-report-progress.sh, Makefile (test-impacted-go): exclude testdata/ Go files from changed-file lint/impacted-test package selection. Analyzer fixtures intentionally contain errorlint/govet violations and are not part of ./cmd/... ./pkg/..., so editing them previously broke the local pre-PR gate with unrelated pre-existing findings.

The same misattribution also caused a false negative for %v on the true error argument; that is fixed by the same change.


Branch refresh requested by pr-sous-chef. Run: https://github.com/github/gh-aw/actions/runs/31461992299> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.4 AIC · ⌖ 5.05 AIC · ⊞ 8.5K ·

Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix false positive in errorfwrapv for correct %w wrapping Fix errorfwrapv false positive on explicit arg index before dynamic * width Aug 11, 2026
Copilot AI requested a review from pelikhan August 11, 2026 04:51
@pelikhan
pelikhan marked this pull request as ready for review August 11, 2026 05:00
Copilot AI balanced review requested due to automatic review settings August 11, 2026 05:00

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

Fixes explicit argument-index tracking in errorfwrapv and adjusts validation handling for analyzer fixtures.

Changes:

  • Defers format value-index attribution until after width parsing.
  • Adds an indexed dynamic-width %w regression fixture.
  • Excludes testdata packages from changed-package validation.
Show a summary per file
File Description
pkg/linters/errorfwrapv/errorfwrapv.go Updates format argument parsing.
pkg/linters/errorfwrapv/testdata/src/errorfwrapv/errorfwrapv.go Adds the regression fixture.
scripts/agent-report-progress.sh Excludes fixtures from package linting.
Makefile Excludes fixtures from impacted-test discovery.

Review details

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment on lines 195 to 196
valueArgIdx := 0
hasExplicitValueArg := false
Comment on lines +53 to +55
func GoodIndexedDynamicWidthWrap(width int, err error) error {
return fmt.Errorf("%[1]*w", width, err)
}
Comment thread Makefile
exit 1; \
fi; \
CHANGED_GO_FILES=$$({ git diff --name-only --diff-filter=ACDMR "$$BASE_COMMIT"; git ls-files --others --exclude-standard; } | sort -u | grep -E '\.go$$' || true); \
CHANGED_GO_FILES=$$({ git diff --name-only --diff-filter=ACDMR "$$BASE_COMMIT"; git ls-files --others --exclude-standard; } | sort -u | grep -E '\.go$$' | grep -v -E '(^|/)testdata/' || true); \
@github-actions

github-actions Bot commented Aug 11, 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 11, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship. No over-engineering found: diff removes speculative code (net -6 lines) and adds minimal, non-abstracted testdata filtering. No unnecessary complexity to cut.

Generated by Ponytail Reviewer for #51932

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • api.individual.githubcopilot.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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

No ADR enforcement needed: PR #51932 does not have the 'implementation' label and has only 6 new lines of code in business logic directories (threshold: 100).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@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 — requesting changes on a regression risk and missing test coverage.

Key Themes

Issues

  • Regression risk (/diagnosing-bugs): Removing the pre-flag index parse breaks %[n]flag+verb and %[n]widthverb patterns (e.g. %[2]+v, %[2]10v). The subsequent index parse only fires when * is present, so explicit indexes before flags or fixed widths are silently dropped — a correctness regression.
  • Incomplete test coverage (/tdd): The PR only adds a Good case for %[1]*w. The PR description claims the same change also fixes a false negative for %v on the real error argument, but no test exercises that path.
  • testdata filter is too broad (Makefile/script): Excluding all testdata/ files from impacted-test detection means a fixture-only edit reports "No changed Go files" and skips test-impacted-go entirely, even though analyzer tests depend on those fixtures.

Positive Highlights

  • Root cause is correctly identified.
  • PR description is clear and includes a minimal reproducer.
  • Script change correctly guards package_dir.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 18.6 AIC · ⌖ 6.53 AIC · ⊞ 7.1K
Comment /matt 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.

The fix is correct. Moving parseFormatArgIndex to after consumeFormatWidthOrPrecision properly handles the %[1]*w case (explicit index before dynamic * width) without regressing other formats.

For %[2]v-style formats (index before verb with no width), the flags loop only consumes -+#0 characters and never consumes [, so the post-width parseFormatArgIndex call at line 212 correctly picks up the explicit index. The previous inline comment about %[2]+v regression was a false positive.

The Makefile and agent-report-progress.sh changes correctly exclude testdata/ from impacted-test and lint runs, avoiding treating analyzer fixtures as real packages.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 27.3 AIC · ⌖ 6.25 AIC · ⊞ 5.4K

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

Copy link
Copy Markdown
Contributor

This is a sharp fix to the errorfwrapv linter! The PR correctly addresses the false positive reported in #51928 where explicit argument indices before dynamic * width specifiers were being misattributed, causing correctly-wrapped errors to be flagged as missing %w.

What looks great:

  • The fix is surgical: removes the premature, speculative index parsing causing the bug
  • Regression test validates the exact scenario
  • Testdata exclusion in Makefile and scripts/agent-report-progress.sh prevents CI noise from linting analyzer test fixtures
  • Clear, thorough PR description tracing the root cause

This PR is ready for review and merge. Focused, well-tested, and addresses a real correctness bug.

Generated by ✅ Contribution Check · auto · 49.8 AIC · ⌖ 3.79 AIC · ⊞ 8.8K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@-

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 12.4 AIC · ⌖ 5.05 AIC · ⊞ 8.5K ·
Comment /souschef to run again

@pelikhan
pelikhan deleted the copilot/errorfwrapv-fix-argument-index-bug branch August 11, 2026 06:23
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.2

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

errorfwrapv: explicit index before dynamic width star causes false-positive missing wrap on correctly-wrapped errors

4 participants