Skip to content

Add errorsnewerrorstring analyzer - #76920

Merged
pelikhan merged 6 commits into
mainfrom
copilot/linter-minererrors-new-error-string
Nov 11, 2026
Merged

pelikhan merged 6 commits into
mainfrom
copilot/linter-minererrors-new-error-string

Conversation

Copilot AI commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

errors.New(err.Error()) converts an error to plain text, losing the original error chain and breaking errors.Is and errors.As.

  • Analyzer: Add errorsnewerrorstring to report this pattern when the receiver implements error. Supports parentheses and nolint suppression.
  • Registration and docs: Register the analyzer, document it, and track it as not yet CI-enforced.
  • Example: Return the original error or wrap it with %w:
    return fmt.Errorf("load config: %w", err)

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Add errorsnewerrorstring linter for errors.New(err.Error()) Add errorsnewerrorstring analyzer Nov 11, 2026
Copilot AI requested a review from gh-aw-bot November 11, 2026 18:48
@pelikhan
pelikhan marked this pull request as ready for review November 11, 2026 19:22
Copilot AI dynamic review requested due to automatic review settings November 11, 2026 19:22
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

Generated by PR Specification Reviewer for #76920

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt61 medium · ~3 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 181 · ◷

Generated by Ponytail Reviewer for #76920

@github-actions

This comment has been minimized.

@github-actions

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

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

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

No active review issues require changes before approval.

No open issues 🎉

What changed in this PR

Adds errorsnewerrorstring to gh-aw’s custom Go analyzers, addressing #76916 by detecting error-to-string conversions that discard error identity and break errors.Is / errors.As matching.

Changes:

  • Detects errors.New(err.Error()) with receiver-type checks, parenthesis handling, and nolint support.
  • Adds analyzer fixtures covering detection, suppression, and negative cases.
  • Registers and documents the analyzer while deferring CI enforcement pending an audit.
File Description
pkg/​linters/​spec_test.go Adds the analyzer to documented API checks and updates the count.
pkg/​linters/​registry.go Registers the analyzer.
pkg/​linters/​README.md Documents the rule and analyzer usage.
pkg/​linters/​errorsnewerrorstring/​testdata/​src/​errorsnewerrorstring/​errorsnewerrorstring.go Adds positive, negative, and suppression fixtures.
pkg/​linters/​errorsnewerrorstring/​errorsnewerrorstring.go Implements detection and diagnostic reporting.
pkg/​linters/​errorsnewerrorstring/​errorsnewerrorstring_test.go Runs the analyzer against its fixtures.
pkg/​linters/​doc.go Updates the analyzer catalog and count.
pkg/​linters/​doc_sync_test.go Records the analyzer as not yet CI-enforced.

Review effort: Balanced (auto)

@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.

Reviewed the changed analyzer and registration/docs updates. I found no actionable correctness, regression, or security issues on the changed lines. The implementation correctly resolves the imported errors package, checks the Error() receiver type, honors generated-file and nolint handling, and includes focused analysistest coverage.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (>100 new lines in pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/76920-add-errorsnewerrorstring-analyzer.md. Review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

Precedent: earlier linter additions have ADRs (for example docs/adr/33834-add-file-close-not-deferred-linter.md), so this follows existing practice.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff.

  2. Complete the missing sections. Add context the gate could not infer, refine the rationale, and list the alternatives you actually considered. Resolve the [TODO: verify] marker in Context.

  3. Commit the finalized ADR to docs/adr/ on your branch.

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-76920: Add errorsnewerrorstring Analyzer (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide? Why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/, numbered by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 8.5K · ◷
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.

Skills-Based Review 🧠

Applied /tdd and /codebase-design. The analyzer logic is sound, and go test ./pkg/linters/... passes. Three non-blocking follow-ups are posted as inline comments.

📋 Key Themes & Highlights

Key Themes

  • Count drift: spec_test.go says 95 analyzers, but documentedAnalyzers() and doc.go both list 96.
  • Test coverage: the pointer-receiver Error() path is flagged but not pinned by a // want case.
  • Naming: goodFmtWrap describes fmt.Errorf/%w, but the body uses errors.Join.

Positive Highlights

  • ✅ Receiver check uses types (ImplementsError) rather than name matching, so the differentErrorMethod negative case is handled correctly.
  • ✅ nolint suppression and generated-file skipping follow the same pattern as sibling analyzers.
  • ✅ The analyzer is registered in registry.go, doc.go, the README, and spec_test.go, and is correctly listed in notYetEnforced.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again

Comment thread pkg/linters/spec_test.go Outdated

// documentedAnalyzers returns the analyzer subpackages documented in the README
// "Public API > Subpackages" table. The README documents 94 analyzer
// "Public API > Subpackages" table. The README documents 95 analyzer

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.

[/codebase-design] Count drift: this comment says the README documents 95 analyzers, but documentedAnalyzers() now lists 96 entries, and doc.go also says 96. Update this comment to 96 so the spec comment matches the list.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the count comment to 96. Commit: 3ce9546.

return errors.New(err.Error()) // want `errors\.New\(err\.Error\(\)\) discards the original error`
}

func badConcrete(err testError) error {

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.

[/tdd] Test gap: the analyzer does flag errors.New(v.Error()) when Error has a pointer receiver and v is an addressable value (verified locally), but no // want case pins that behavior. Add one so a future change to the receiver check cannot silently alter it.

💡 Suggested test
type ptrError struct{}

func (*ptrError) Error() string { return "ptr error" }

func badPointerReceiver() error {
	var err ptrError
	return errors.New(err.Error()) // want `discards the original error`
}

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the addressable value/pointer-receiver case with a diagnostic expectation; the analyzer fixture test passes. Commit: 3ce9546.

return err
}

func goodFmtWrap(err error) error {

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.

[/tdd] Naming mismatch: goodFmtWrap suggests a fmt.Errorf with %w wrap, but the body uses errors.Join. Rename it (for example goodErrorsJoin) so test names read as specifications.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed the fixture to goodErrorsJoin to match its errors.Join body. Commit: 3ce9546.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/linters/spec_test.go:125): address unresolved feedback - Review comment
  3. Review (pkg/linters/errorsnewerrorstring/testdata/src/errorsnewerrorstring/errorsnewerrorstring.go:13): address unresolved feedback - Review comment
  4. Review (pkg/linters/errorsnewerrorstring/testdata/src/errorsnewerrorstring/errorsnewerrorstring.go:25): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "e96149c6fa5a0183bb4419eb848ad9b025386098",
  "kind": "requested",
  "schema_version": "1",
  "state": "6f8051011d37e0fffeb4b1a14af9e24f68515756628f5b73ee1874cd45073aa3",
  "work": [
    "04980fc77481c413ffc003a4be66484952c9c07a2e9811b4a0c72d155e807bc1",
    "2adc7c03d3558eb2ebbae10872ad563ea81a5a5b5cda7175c9b0b78109d83c55",
    "3ab37ed20c3e536a5bf95822534465fa40cf8ab8163d01f21038f76f62e2a01f"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 6.9K · ◷
Comment /souschef to run again

Copilot AI and others added 2 commits November 11, 2026 19:59
…rrors-new-error-string

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
@pelikhan
pelikhan merged commit 8c091a7 into main Nov 11, 2026
48 checks passed
@pelikhan
pelikhan deleted the copilot/linter-minererrors-new-error-string branch November 11, 2026 21:47
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.3

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.

[linter-miner] Add errorsnewerrorstring linter for errors.New(err.Error())

4 participants