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: go work use panics when given a file #51749

Closed
JohnAnthony opened this issue Mar 17, 2022 · 8 comments
Closed

cmd/go: go work use panics when given a file #51749

JohnAnthony opened this issue Mar 17, 2022 · 8 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. Suggested Issues that may be good for new contributors looking for work to do.

Comments

@JohnAnthony
Copy link

JohnAnthony commented Mar 17, 2022

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

$ go version
1.18

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
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/ja/go/bin"
GOCACHE="/home/ja/.cache/go-build"
GOENV="/home/ja/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ja/go/pkg/mod"
GONOPROXY="*"
GONOSUMDB="*"
GOOS="linux"
GOPATH="/home/ja/go"
GOPRIVATE="*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/ja/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/ja/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4125566826=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ mkdir work
$ cd work
$ go work init
$ touch iamafile
$ go work use iamafile

What did you expect to see?

A graceful error around having been provided a file instead of a folder

What did you see instead?

go: stat /home/ja/work/iamafile/go.mod: not a directory
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x81d565]

goroutine 1 [running]:
cmd/go/internal/workcmd.runUse.func1({0x7ffc8a10a7ed?, 0x0?})
        /usr/local/go/src/cmd/go/internal/workcmd/use.go:97 +0x165
cmd/go/internal/workcmd.runUse({0xadc718?, 0xc000122000?}, 0xc00014c510?, {0xc00013a030, 0x1, 0x2?})
        /usr/local/go/src/cmd/go/internal/workcmd/use.go:112 +0xa8a
main.invoke(0xdb7660, {0xc00013a020, 0x2, 0x2})
        /usr/local/go/src/cmd/go/main.go:218 +0x2ee
main.main()
        /usr/local/go/src/cmd/go/main.go:175 +0x78e
@seankhliao seankhliao changed the title cmd/go: go work use has segmentation violation when given a file rather than a folder cmd/go: go work use panics when given a file Mar 17, 2022
@seankhliao seankhliao added NeedsFix The path to resolution is known, but the work has not been done. GoCommand cmd/go labels Mar 17, 2022
@seankhliao
Copy link
Member

cc @bcmills @matloob

@mvdan mvdan added the Suggested Issues that may be good for new contributors looking for work to do. label Mar 17, 2022
@mvdan
Copy link
Member

mvdan commented Mar 17, 2022

This seems like a good candidate for someone's first contribution, by the way. Just make sure to look at how recent bugfixes in go work were implemented, read https://go.dev/doc/contribute, and include a test case.

@JohnAnthony
Copy link
Author

I'd be interested in working on this as a first contribution

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/393615 mentions this issue: cmd/go: prevent go work use panic when given a file

@bcmills
Copy link
Contributor

bcmills commented Mar 17, 2022

@gopherbot, please backport to Go 1.18. (This is a user-facing panic in go work use.)

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #51764 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

notfilippo added a commit to notfilippo/go that referenced this issue Mar 21, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841 golang#51749
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/394154 mentions this issue: cmd/go: prevent panic in go work use

notfilippo pushed a commit to notfilippo/go that referenced this issue Mar 21, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841 golang#51749
notfilippo pushed a commit to notfilippo/go that referenced this issue Mar 31, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841 golang#51749
notfilippo pushed a commit to notfilippo/go that referenced this issue Apr 4, 2022
Check if paths passed as arguments are existing directories.

Fixes golang#51841
Fixes golang#51749
gopherbot pushed a commit that referenced this issue Apr 4, 2022
Check if paths passed as arguments are existing directories.

Fixes #51841
Fixes #51749

Change-Id: Icfd148627e6f2c4651d6f923a37d413e68c67f6c
GitHub-Last-Rev: 77fffa7
GitHub-Pull-Request: #51845
Reviewed-on: https://go-review.googlesource.com/c/go/+/394154
Trust: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/397994 mentions this issue: [release-branch.go1.18] cmd/go: prevent go work use panic when given a file

gopherbot pushed a commit that referenced this issue Apr 5, 2022
…a file

The current implementation fails to identify that an argument to go work
use is a file when expecting a directory, and panics when attempting to
access it as a directory. This change checks arguments are directories
and generates an error otherwise.

Fixes #51764
Updates #51749

Change-Id: If8f69d233409e93fcf391a8774bace74c031c986
Reviewed-on: https://go-review.googlesource.com/c/go/+/393615
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit a84ef50)
Reviewed-on: https://go-review.googlesource.com/c/go/+/397994
Reviewed-by: Cherry Mui <cherryyz@google.com>
@golang golang locked and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants