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

x/tools/go/analysis/passes/slog: misleading vet message for variadic params in Info functions #65154

Closed
raghvenders opened this issue Jan 18, 2024 · 5 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@raghvenders
Copy link
Contributor

Go version

devel go1.22-20a03fc713 Mon Dec 11 17:49:10 2023 +0000

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Ragul\AppData\Local\go-build
set GOENV=C:\Users\Ragul\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Ragul\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Ragul\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\Ragul\golang\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\Ragul\golang\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.22-20a03fc713 Mon Dec 11 17:49:10 2023 +0000
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Ragul\AppData\Local\Temp\go-build3109705574=/tmp/go-build -gno-record-gcc-switches

What did you do?

For Every did you do -> did see happen

  • when i do, slog.Info("Hello Amsterdam", 1)
  • Then I changed it to "1"
  • It is expecting a value, so i added a value

slog.Info("Hello Amsterdam", "1", 1)

What did you see happen?

  • slog.Info arg "1" should be a string or a slog.Attr (possible missing key or value)
  • call to slog.Info missing a final values slog

What did you expect to see?

If it says up front, it expects key as string and value of any would be great. It is always expected in even numbers.
I would just go little further and ask, instead of variadic why did we not consider having a map[string]any or ...map[string]any as it already expects thinks in a key, value missing and strictly key being the string.

@raghvenders
Copy link
Contributor Author

raghvenders commented Jan 18, 2024

CC @jba Including @timothy-king as it seems some vet has already been worked upon #59407. May be more verbose have (int) want (string,int)

@seankhliao
Copy link
Member

I believe this is working as intended.
See slog discussion for reasoning

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2024
@timothy-king
Copy link
Contributor

Let's be a bit more concrete https://go.dev/play/p/NCfv0h9tCIv?v=gotip :

slog.Info("Hello Amsterdam", 1)       // vet: ./prog.go:8:31: slog.Info arg "1" should be a string or a slog.Attr (possible missing key or value)

	slog.Info("Hello Amsterdam", "1")    // vet: ./prog.go:9:2: call to slog.Info missing a final value
	slog.Info("Hello Amsterdam", "1", 1) // no vet output

This example prints:

2009/11/10 23:00:00 INFO Hello Amsterdam !BADKEY=1
2009/11/10 23:00:00 INFO Hello Amsterdam !BADKEY=1
2009/11/10 23:00:00 INFO Hello Amsterdam 1=1

The vet diagnostics themselves seem to be correctly pointing out and describing API usage problems. But there is always room for improving how to present and word diagnostics. It is a bit of an art to get pithy, correct, and helpful messages. IMO the messages are pithy and correct which vet messages must be. But perhaps insufficiently helpful.

There are also multiple places to display information which are under different constraints, i.e. the analyzer package website can give long examples in detail and we can try to highlight the url to get users there. So there we have a few different things we could do to try to be more helpful.

Do you have a suggestion for how would you prefer the diagnostic to have been worded? Or whether there was information or an example that would have made this clearer?

I would just go little further and ask, instead of variadic why did we not consider having a map[string]any or ...map[string]any as it already expects thinks in a key, value missing and strictly key being the string.

This would be a new API or a backwards incompatible change. In either case, it would be its own proposal.

@timothy-king timothy-king reopened this Jan 18, 2024
@timothy-king timothy-king added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. Analysis Issues related to static analysis (vet, x/tools/go/analysis) labels Jan 18, 2024
@seankhliao seankhliao changed the title golang.org/x/tools/: slog - Misleading vet message for variadic params in Info functions x/tools/go/analysis/passes/slog: misleading vet message for variadic params in Info functions Jan 19, 2024
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 19, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jan 19, 2024
@jba
Copy link
Contributor

jba commented Jan 22, 2024

Maps are expensive to create. We wanted logging to be fast.

@raghvenders
Copy link
Contributor Author

@timothy-king , may be I will come with different issue as i tried currently going about api directly on IDE. But if we go through documentation and start including api, it is concise enough. May be we can propagate some or repeat with a doc link.

@jba - make sense , we need to keep order and i had gone through discussion about ...kv , where kv is a struct and memory allocation discussion.

So closing the issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) Tools This label describes issues relating to any tools in the x/tools repository. 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