Skip to content
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

cmd/vet: spurious error message non-constant format string in call to mypkg/errors.New #71695

Closed
amnonbc opened this issue Feb 12, 2025 · 9 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@amnonbc
Copy link

amnonbc commented Feb 12, 2025

Go version

go version go1.24.0 darwin/arm64

Output of go env in your module/workspace:

GOVERSION='go1.24.0'

What did you do?

ran go vet

What did you see happen?

errors the of form

non-constant format string in call to mypkg/errors.New

This is a message is incorrect, as mypkg/errors.New does explicitly allow format strings.

The message would have been correct if I would have called errors.New() from stdlib
but mypkg/errors.New is a different function with a different signature.

What did you expect to see?

no errors

@seankhliao
Copy link
Member

please show a complete reproducer.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 12, 2025
@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 12, 2025
@seankhliao seankhliao changed the title Go vet spurious error message non-constant format string in call to mypkg/errors.New cmd/vet: spurious error message non-constant format string in call to mypkg/errors.New Feb 13, 2025
@adonovan
Copy link
Member

To be clear: the intent of the check is catch mistakes of this form:

https://go.dev/play/p/6dPT8b-lyZa

func main() {
	oops("this is 100% wrong!")
}

func oops(s string) {
	log.Printf(s) // "2009/11/10 23:00:00 this is 100%!w(MISSING)rong!"
}

@amnonbc
Copy link
Author

amnonbc commented Feb 13, 2025

To be clear: the intent of the check is catch mistakes of this form:

https://go.dev/play/p/6dPT8b-lyZa

func main() {
oops("this is 100% wrong!")
}

func oops(s string) {
log.Printf(s) // "2009/11/10 23:00:00 this is 100%!w(MISSING)rong!"
}

Thanks Alan.

On the other hand, if we had

func oops(s string, args ...any)  {
    log.Printf(s, args...)
}

we would probably not want to see a go vet warning.

@seankhliao
Copy link
Member

I believe the check is transitive:

package main

import "log"

func main() {
	var s string

	oops("foo") // won't warn
	oops(s)     // will warn
}

func oops(s string, args ...any) {
	log.Printf(s, args...)
}

@ianlancetaylor
Copy link
Member

In any case you won't get a warning if arguments are being passed.

If you think there is a bug here, please show us the code that is triggering an incorrect warning. Thanks.

@amnonbc
Copy link
Author

amnonbc commented Feb 13, 2025

In any case you won't get a warning if arguments are being passed.

If you think there is a bug here, please show us the code that is triggering an incorrect warning. Thanks.

OK, I'll try to extract a small example this weekend.

@amnonbc
Copy link
Author

amnonbc commented Feb 14, 2025

Alan, Ian and Sean
Thanks for your explanations.

I have now checked a sample of these errors generated when running go vet over my codebase
and see that the errors are correct (or at least reasonable).

I am therefore closing the ticket.

@amnonbc amnonbc closed this as completed Feb 14, 2025
@ianlancetaylor
Copy link
Member

Thanks for following up.

taylorsilva added a commit to concourse/concourse that referenced this issue Feb 19, 2025
This is the main error we got when compiling everything:

golang/go#71695

Signed-off-by: Taylor Silva <dev@taydev.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants