Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[linter-miner] linter: add errorfwrapv — flag fmt.Errorf using %v to wrap errors instead of %w #39263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
[linter-miner] linter: add errorfwrapv — flag fmt.Errorf using %v to wrap errors instead of %w #39263
Changes from 1 commit
e746b8a3b21d26ce189fdbdda0947db30f81eafd1a551cfee3b971b9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Check failure on line 19 in pkg/linters/errorfwrapv/errorfwrapv.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd]
parseFormatVerbsscans past[n]but never extracts the numeric index —argIdxstill increments sequentially. Forfmt.Errorf("%[2]v occurred: %[1]s", name, err), the verb%[2]vis recorded atargIdx=0 → callArgIdx=1 = name(not an error), silently missing the real error arg — a false negative.💡 Suggested fix
Extract the integer between
[and]and use it (0-based) as the argument index for this verb, and reset the sequential counter:Add a test fixture for the explicit-index case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd]
%*v(width taken from an argument, e.g.fmt.Errorf("%-*v: %v", 10, name, err)) is not handled. The parser exits the width loop on*and records*as the verb, consumingargIdx=0. The actualvverb is then skipped. For the second%v, the code mapsargIdx=1 → call.Args[2] = name— missingerratcall.Args[3]— false negative.💡 Suggested fix
Handle
*in the width (and precision) slot: treat it as consuming one argument index before reading the verb.Add a test fixture:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] Good that
BadVWrapExtrashows%valongside a non-error arg — that's a useful positive case. Consider also adding a fixture for a concreteerror-implementing type passed directly (not via theerrorinterface variable) to confirmtypes.Implementshandles pointer receivers correctly.💡 Suggested fixture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] The nolint suppression path (analyzer lines 79–81) has no fixture. If
nolint.HasDirectivewere accidentally removed or inverted, no test would catch it.💡 Suggested fixture to add
Uh oh!
There was an error while loading. Please reload this page.