Go: Check err != nil is true on nil error

Created on 7 May 2016  ·  1Comment  ·  Source: golang/go

Go version

go version go1.6.1 linux/amd6

Environment

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/rot256/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

The distro is Debian (unstable)

Reproducing

See this program for a POC

Notes

I expected the last line to not be printed,
since "Junk" returns nil (and the program typechecks)
I expected err != nil to be false.

I don't know if this is intended behavior, but it seems error prone.

FrozenDueToAge

Most helpful comment

>All comments

Was this page helpful?
0 / 5 - 0 ratings