You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I went to create a temporary go.mod file in /tmp to test something. As per https://golang.org/cl/129063, /<temp-dir>/go.mod is generally ignored - not realising this, I ran go mod tidy and was slightly surprised to see a panic printed.
What did you expect to see?
With Go 1.17 a warning is displayed, which seems reasonable:
$ docker run -it --entrypoint=/bin/sh golang:1.17-alpine
/go # go version
go version go1.17.8 linux/amd64
/go # cd /tmp
/tmp # go mod init tmp
go: creating new go.mod: module tmp
/tmp # go mod tidy
go: warning: ignoring go.mod in system temp root /tmp
go: warning: "all" matched no packages
/tmp # echo $?
0
/tmp #
What did you see instead?
With Go 1.18 the same warning is displayed, but there is also a panic relating to a nil pointer dereference:
$ docker run -it --entrypoint=/bin/sh golang:1.18-alpine
/go # go version
go version go1.18 linux/amd64
/go # cd /tmp
/tmp # go mod init tmp
go: creating new go.mod: module tmp
/tmp # go mod tidy
go: warning: ignoring go.mod in system temp root /tmp
go: warning: "all" matched no packages
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x78846d]
goroutine 1 [running]:
cmd/vendor/golang.org/x/mod/modfile.(*File).AddGoStmt(0x0, {0xc0000a2148, 0x4})
/usr/local/go/src/cmd/vendor/golang.org/x/mod/modfile/rule.go:928 +0x4d
cmd/go/internal/modload.LoadPackages({0xadc718?, 0xc0000a2000}, {{0x0, 0x0}, 0xc00012dda0, 0x1, {0x0, 0x0}, 0x1, 0x1, ...}, ...)
/usr/local/go/src/cmd/go/internal/modload/load.go:426 +0x74d
cmd/go/internal/modcmd.runTidy({0xadc718, 0xc0000a2000}, 0xc0000ce408?, {0xc00009c170?, 0x4?, 0x2?})
/usr/local/go/src/cmd/go/internal/modcmd/tidy.go:114 +0x198
main.invoke(0xdb6380, {0xc00009c170, 0x1, 0x1})
/usr/local/go/src/cmd/go/main.go:218 +0x2ee
main.main()
/usr/local/go/src/cmd/go/main.go:175 +0x78e
/tmp # echo $?
2
/tmp #
The text was updated successfully, but these errors were encountered:
In cmd/go/internal/modload/load.go, LoadPackages function fails into a panic due to nil pointer. Adding nil check would solve this issue.
Other mod commands like mod vendor or mod why also use the function, but as a result of if statement, no panics occur with them. This issue would only occur with mod tidy.
Hi all, I am still having this issue (ignoring go.mod in system temp root /tmp) with golang 1.20
root@c2b53323c59c:/tmp# pwd
/tmp
root@c2b53323c59c:/tmp# ls
Dockerfile README.md conf go.mod go.sum main.go static
root@c2b53323c59c:/tmp# go version
go version go1.20.1 linux/arm64
root@c2b53323c59c:/tmp# go mod tidy
go: warning: ignoring go.mod in system temp root /tmp
go: warning: "all" matched no packages
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I went to create a temporary go.mod file in
/tmp
to test something. As per https://golang.org/cl/129063,/<temp-dir>/go.mod
is generally ignored - not realising this, I rango mod tidy
and was slightly surprised to see a panic printed.What did you expect to see?
With Go 1.17 a warning is displayed, which seems reasonable:
What did you see instead?
With Go 1.18 the same warning is displayed, but there is also a panic relating to a nil pointer dereference:
The text was updated successfully, but these errors were encountered: