golang/go

go/build: ImportDir/Import no longer return os not found error for missing dir on local files

Open

#21,923 opened on Sep 18, 2017

View on GitHub
 (12 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.9

Does this issue reproduce with the latest release?

Yes. Was not present before latest release.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/mfarina/Code/go" GORACE="" GOROOT="/usr/local/Cellar/go/1.9/libexec" GOTOOLDIR="/usr/local/Cellar/go/1.9/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ml/55r2m1jd38x068q85txj8cvc0000gn/T/go-build428826794=/tmp/go-build -gno-record-gcc-switches -fno-common" CXX="clang++" CGO_ENABLED="1" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config"

What did you do?

I have code that uses ImportDir (from the go/build package) to look at the packages used by another package. If there is an error from ImportDir the automation acts on the error to try and fix the problem.

What did you expect to see?

I expected a missing directory to cause the returned error to be able to be detected by os.IsNotExist. This is how previous version of Go worked.

What did you see instead?

The returned error was in the form of

   fmt.Errorf("cannot find package %q in:\n\t%s", path, p.Dir)

In 1.8.3 (and before), the Import function would fall through to ctxt.readDir that used io.ReadDir...

https://github.com/golang/go/blob/352996a381701cfa0c16e8de29cbde8f3922182f/src/go/build/build.go#L171-L177

In 1.9 The code is a little different for local files. Instead the code stops at...

https://github.com/golang/go/blob/c8aec4095e089ff6ac50d18e97c3f46561f14f48/src/go/build/build.go#L687-L695

You can no longer rely on os.IsNotExist to detect missing package directories.

This change was not documented in the release notes, either.

Contributor guide