-
Notifications
You must be signed in to change notification settings - Fork 50
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
poll: Continue(): use format.Message for formatting #279
Conversation
7e0fb1f
to
97d125f
Compare
Windows failure looks unrelated; not sure what's causing it though;
|
fix for the panic in this PR: |
@dnephin @vdemeester PTAL 🤗 |
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.
It is possible this could be a breaking change for some code, but it seems unlikely.
The problem the linter is complaining about is still there. Ex:
errorMsg := "invalid %size% value '4f'"
poll.Continue(errorMsg)
// invalid %!s(MISSING)ize%!v(MISSING)alue '4f'
Maybe there should have been both a Continue
and Continuef
.
Another option would be to add an issues.exclude-rule
to https://github.com/moby/moby/blob/master/.golangci.yml:
// ignore possible invalid format strings in test helper
- path: _test\.go
linters: [govet]
text: non-constant format string in call to gotest.tools/v3/poll.Continue
or to be safe
return poll.Continue("%v", msg)
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.
Ah, I forgot Continue handled this already!
Would something that keeps the function signature work?
func Continue(message string, args ...interface{}) Result {
return result{message: format.Message(append([]interface{}{message}, args...)...)}
Yes, works for me! I was initially considering doing that, but then went for the Let me update. |
Current versions of govet check for printf functions called with a format string, but no arguments. This results in linting errors for uses of Continue with a fixed message, for example: poll/poll.go:154:18: printf: non-constant format string in call to gotest.tools/v3/poll.Continue (govet) return Continue(buf.String()) ^ While not explicitly called out in the function's GoDoc, I think the intent was to provide the same behavior as the msgAndArgs arguments in the assert package, which allows for either a literal message (or value), or a format with arguments to be passed. Accepting a non-string variable as first argument would require a change of the function's signature, but we can use the format.Message function internally to fix the linting issue. Signed-off-by: Sebastiaan van Stijn <[email protected]>
97d125f
to
7f28766
Compare
Oh; forgot to coment; I updated with your suggestions; @dnephin PTAL 🤗 |
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.
Thank you!
Current versions of govet check for printf functions called with a format
string, but no arguments. This results in linting errors for uses of Continue
with a fixed message, for example:
While not explicitly called out in the function's GoDoc, I think the intent
was to provide the same behavior as the msgAndArgs arguments in the assert
package, which allows for either a literal message (or value), or a format
with arguments to be passed.
Accepting a non-string variable as first argument would require a change
of the function's signature, but we can use the format.Message function
internally to fix the linting issue.