Repository navigation
Add errorsnewerrorstring analyzer - #76920
Conversation
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: 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.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: 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.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: 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.
|
This comment has been minimized.
This comment has been minimized.
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
There was a problem hiding this comment.
🟢 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, andnolintsupport. - 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)
There was a problem hiding this comment.
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
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (>100 new lines in 📄 Draft ADR committed:
Precedent: earlier linter additions have ADRs (for example 📋 What to do next
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 ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
There was a problem hiding this comment.
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.gosays 95 analyzers, butdocumentedAnalyzers()anddoc.goboth list 96. - Test coverage: the pointer-receiver
Error()path is flagged but not pinned by a// wantcase. - Naming:
goodFmtWrapdescribesfmt.Errorf/%w, but the body useserrors.Join.
Positive Highlights
- ✅ Receiver check uses
types(ImplementsError) rather than name matching, so thedifferentErrorMethodnegative case is handled correctly. - ✅
nolintsuppression and generated-file skipping follow the same pattern as sibling analyzers. - ✅ The analyzer is registered in
registry.go,doc.go, the README, andspec_test.go, and is correctly listed innotYetEnforced.
@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
|
|
||
| // 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 |
There was a problem hiding this comment.
[/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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
[/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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
[/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.
There was a problem hiding this comment.
Renamed the fixture to goodErrorsJoin to match its errors.Join body. Commit: 3ce9546.
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
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"
}
|
…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>
|
🎉 This pull request is included in a new release. Release: |
errors.New(err.Error())converts an error to plain text, losing the original error chain and breakingerrors.Isanderrors.As.errorsnewerrorstringto report this pattern when the receiver implementserror. Supports parentheses andnolintsuppression.%w: