go vet -slog reports no errors, but the key isn't present.
$ go vet -slog ./main.go
$ go run ./main.go
2024/02/16 00:50:48 ERROR The error is %v !BADKEY=<nil>
What did you expect to see?
go vet -slog ./main.go should report an error like ./main.go:7:32: slog.Error arg "x" should be a string or a slog.Attr (possible missing key or value).
Interestingly, if you change the type of x to int, the error fires as you'd expect.
package main
import "log/slog"
func main() {
var x int
slog.Error("The error is %v", x)
}
$ go vet -slog ./main.go
# command-line-arguments
# [command-line-arguments]
./main.go:7:32: slog.Error arg "x" should be a string or a slog.Attr (possible missing key or value)
$ go run ./main.go
2024/02/16 00:52:58 ERROR The error is %v !BADKEY=0
Go version
go version go1.22.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I wrote code that assumed
slog
methods worked likefmt.Printf
, instead of talkingAttr
/key-value pairs:playground
Running
go vet -slog ./main.go
What did you see happen?
go vet -slog
reports no errors, but the key isn't present.What did you expect to see?
go vet -slog ./main.go
should report an error like./main.go:7:32: slog.Error arg "x" should be a string or a slog.Attr (possible missing key or value)
.Interestingly, if you change the type of
x
toint
, the error fires as you'd expect.