Skip to content
Latchkey

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".

go vet
./log.go:12:2: fmt.Printf format %d has arg name of wrong type string

Common 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

  1. Read the verb and the argument type vet names.
  2. Use the correct verb (%s for strings, %d for integers, %v for general values).
  3. Re-run go vet ./... to confirm.
log.go
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 %v only when the exact type is not important.
  • Keep format strings and argument lists in sync when editing.

Frequently asked questions

What causes ""arg ... for %d ... of wrong type""?
Using %d for a string, %s for an int, or %v mismatches produces a vet diagnostic.
How do I fix "arg ... for %d ... of wrong type"?
Match the verb to the argument

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card