go vet "Printf arg of wrong type" in CI
The printf analyzer in go vet checks format verbs against argument types. A %d paired with a string, or a missing argument, is reported and (since Go 1.10) fails go test because vet runs first.
What this error means
go vet or go test reports "Printf format %d has arg name of wrong type string" or "Printf call needs 1 arg but has 0 args".
./log.go:12:2: fmt.Printf format %d has arg name of wrong type stringCommon causes
A verb does not match its argument type
Using %d for a string, %s for an int, or %v mismatches produces a vet diagnostic.
Too few or too many arguments for the format
The number of verbs does not match the number of arguments supplied to the call.
How to fix it
Match the verb to the argument
- Read the verb and the argument type vet names.
- Use the correct verb (
%sfor strings,%dfor integers,%vfor general values). - Re-run
go vet ./...to confirm.
fmt.Printf("user %s id %d\n", name, id)Fix the argument count
Ensure the number of arguments matches the number of verbs in the format string.
How to prevent it
- Run
go vet ./...in CI; printf checks catch these before release. - Prefer
%vonly when the exact type is not important. - Keep format strings and argument lists in sync when editing.