go: net: Make it possible to determine if a lookup error is errNoSuchHost
What version of Go are you using (go version)?
$ go version go version go1.11.1 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/Users/aermakov/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/aermakov/work/go" GOPROXY="" GORACE="" GOROOT="/usr/local/Cellar/go/1.11.1/libexec" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f1/4tjxswld76n6zmb02rmn18bnr4l_7q/T/go-build082609694=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
I’m trying to determine whether a net.LookupHost fails because the DNS record doesn’t exist, or because of other errors. Unfortunately, errNoSuchHost isn’t exposed from net and there are no helper functions or methods to determine the type of net.DNSError. This leaves me with no choice other than string parsing, which is extremely brittle.
What did you expect to see?
I would expect to be able to tell noSuchHost errors from other errors, either by comparing with an exported error or by using a method on net.DNSError.
What did you see instead?
It’s impossible to determine whether net.LookupHost returned an error the DNS record doesn’t exist or any other reasons without resorting to string parsing.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 25 (17 by maintainers)
Go for it.