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

cmd/go: "no go files in <dir>" error missing directory with list -json=<fields> if fields doesn't contain Dir #64946

Closed
matloob opened this issue Jan 3, 2024 · 4 comments
Assignees
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@matloob
Copy link
Contributor

matloob commented Jan 3, 2024

Go version

go version go1.21.4 darwin/amd64

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

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/matloob/Library/Caches/go-build'
GOENV='/Users/matloob/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/matloob/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/matloob/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/qb/r47yxsb14sx6nz0m6_1pglm8004_sl/T/go-build2981270046=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

In the following module

-- mod/go.mod --
module example.com/foo

go 1.21
-- mod/foo/README.md --
empty

run

cd mod
go list -e -json=ImportPath,Error ./foo

What did you expect to see?

{
	"ImportPath": "./foo",
	"Error": {
		"ImportStack": [],
		"Pos": "",
		"Err": "no Go files in /Users/matloob/Desktop/mod/foo"
	}
}

What did you see instead?

{
	"ImportPath": "./foo",
	"Error": {
		"ImportStack": [],
		"Pos": "",
		"Err": "no Go files in "
	}
}
@gopherbot
Copy link

Change https://go.dev/cl/553795 mentions this issue: cmd/go/internal/list: make a copy of the package before zeroing fields

@seankhliao
Copy link
Member

is this the same as #26296 ?

@matloob
Copy link
Contributor Author

matloob commented Jan 8, 2024

is this the same as #26296 ?

I think they're related, but I think this issue would show up even with the fix Alan suggested if -json didn't contain ImportPath because we would zero out the ImportPath field if it's not requested.

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. GoCommand cmd/go labels Jan 9, 2024
@dmitshur dmitshur added this to the Go1.23 milestone Jan 9, 2024
gopherbot pushed a commit that referenced this issue Jan 29, 2024
go list -json=<fields> zeroes out the fields in the package struct
that aren't specified. The problem with this is that some of the fields
have references into other fields: specifically, the NoGoError's
Error() function accesses the package struct's Dir field, so if we
clear it out the error will just print out "no Go files in" without a
directory. Instead, make a copy of the package struct before we zero
out the fields so the original values are still there.

For #64946

Change-Id: I95103e91fa0782bb23a86a965d5eb87cb12654c6
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/553795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
ezz-no pushed a commit to ezz-no/go-ezzno that referenced this issue Feb 18, 2024
go list -json=<fields> zeroes out the fields in the package struct
that aren't specified. The problem with this is that some of the fields
have references into other fields: specifically, the NoGoError's
Error() function accesses the package struct's Dir field, so if we
clear it out the error will just print out "no Go files in" without a
directory. Instead, make a copy of the package struct before we zero
out the fields so the original values are still there.

For golang#64946

Change-Id: I95103e91fa0782bb23a86a965d5eb87cb12654c6
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/553795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
@matloob
Copy link
Contributor Author

matloob commented Apr 29, 2024

This was fixed by golang.org/cl/553795

@matloob matloob closed this as completed Apr 29, 2024
@matloob matloob self-assigned this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants