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

False positive New is a pure function returning errors.New #981

Closed
calmh opened this issue May 1, 2021 · 2 comments
Closed

False positive New is a pure function returning errors.New #981

calmh opened this issue May 1, 2021 · 2 comments

Comments

@calmh
Copy link

calmh commented May 1, 2021

jb@kvin:..v/calmh/nmea-collect % staticcheck -version
staticcheck 2020.2.3 (v0.1.3)
jb@kvin:..v/calmh/nmea-collect % staticcheck -debug.version
staticcheck 2020.2.3 (v0.1.3)

Compiled with Go version: go1.16.3
Main module:
	honnef.co/go/tools@v0.1.3 (sum: h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o=)
Dependencies:
	github.com/BurntSushi/toml@v0.3.1 (sum: h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=)
	golang.org/x/mod@v0.3.0 (sum: h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=)
	golang.org/x/sys@v0.0.0-20210119212857-b64e53b001e4 (sum: h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=)
	golang.org/x/tools@v0.1.0 (sum: h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=)
	golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 (sum: h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=)
jb@kvin:..v/calmh/nmea-collect % go version
go version go1.16.3 darwin/amd64
jb@kvin:..v/calmh/nmea-collect % go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jb/Library/Caches/go-build"
GOENV="/Users/jb/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jb/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jb/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.3/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jb/dev/calmh/nmea-collect/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0r/vt88n3bd6cz3b7pz29x09pd40000gp/T/go-build2479615612=/tmp/go-build -gno-record-gcc-switches -fno-common"
jb@kvin:..v/calmh/nmea-collect % staticcheck
forward_udp.go:78:10: New is a pure function but its return value is ignored (SA4017)
jb@kvin:..v/calmh/nmea-collect %
func (f *udpForwarder) Serve(ctx context.Context) error {
	dsts := make([]net.Conn, 0, len(f.addrs))
	for _, addr := range f.addrs {
		dst, err := net.Dial("udp", addr)
		if err != nil {
			log.Printf("Can't forward to %s: %v", addr, err)
			continue
		}
		defer dst.Close()
		dsts = append(dsts, dst)
		dstAddr := dst.RemoteAddr().String()
		aisSentPackets.WithLabelValues(dstAddr)
		aisSentBytes.WithLabelValues(dstAddr)
		aisSendErrors.WithLabelValues(dstAddr)
	}
	if len(dsts) == 0 {
		return errors.New("no UDP forward destination")
		// ^^ "New is a pure function but its return value is ignored (SA4017)"
	}
        ...

Making the log+print in the setup loop an error return makes the complaint go away, but I'm not sure why it has that effect.

https://github.com/calmh/nmea-collect/blob/71f3489ea47e79fe0f9e07e8261b409e0508901a/forward_udp.go#L78

@calmh calmh added false-positive needs-triage Newly filed issue that needs triage labels May 1, 2021
@dominikh
Copy link
Owner

dominikh commented May 1, 2021

This should be fixed on the master branch. I will make a new release with the fix included shortly as well.

@dominikh dominikh added duplicate and removed needs-triage Newly filed issue that needs triage labels May 1, 2021
@dominikh
Copy link
Owner

dominikh commented May 1, 2021

Confirmed fixed on master, and I've just released version 2020.2.4 with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants