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: mod tidy panics when there's no Go files but a go.mod #26808

vrischmann opened this issue Aug 4, 2018 · 2 comments


None yet
5 participants
Copy link

commented Aug 4, 2018

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

go version devel +65fa2b615b Fri Aug 3 23:35:53 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

No (but does using Go 1.11beta3)

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

Linux amd64

What did you do?

While playing around with Docker trying to build a cache layer from Go modules I found a case where go mod tidy panics.
At that point there were no Go files, only go.mod and go.sum.

Turns out it is easily reproducible: in an empty directory, adding only a go.mod file with module is sufficient to trigger the panic.
This is of course not a valid use case but I don't think the command should panic.

What did you expect to see?

Not a panic.

What did you see instead?

panic: runtime error: slice bounds out of range
goroutine 1 [running]:
cmd/go/internal/modload.(*mvsReqs).required(0xc00024b030, 0xc000270c26, 0x7, 0x0, 0x0, 0xc00012b4f8, 0x40f639, 0x8e4980, 0xc00027fba8, 0xc00012b598)
        /usr/local/go/src/cmd/go/internal/modload/load.go:794 +0x1232
cmd/go/internal/modload.(*mvsReqs).Required.func1(0xc0001e1524, 0x90fd00)
        /usr/local/go/src/cmd/go/internal/modload/load.go:724 +0x83
cmd/go/internal/par.(*Cache).Do(0xc00024b048, 0x90fd00, 0xc0001e1500, 0xc00012b708, 0xc00012b8d0, 0xc00012b810)
        /usr/local/go/src/cmd/go/internal/par/work.go:128 +0xd6
cmd/go/internal/modload.(*mvsReqs).Required(0xc00024b030, 0xc000270c26, 0x7, 0x0, 0x0, 0xc00024b030, 0x70, 0x68, 0x9218e0, 0x0)
        /usr/local/go/src/cmd/go/internal/modload/load.go:723 +0x10f
cmd/go/internal/modcmd.modTidyGoSum.func1(0xc000270c26, 0x7, 0x0, 0x0)
        /usr/local/go/src/cmd/go/internal/modcmd/tidy.go:80 +0x10b
        /usr/local/go/src/cmd/go/internal/modcmd/tidy.go:87 +0x164
cmd/go/internal/modcmd.runTidy(0xd4eda0, 0xc0000a6080, 0x0, 0x0)
        /usr/local/go/src/cmd/go/internal/modcmd/tidy.go:66 +0x513
        /usr/local/go/src/cmd/go/main.go:218 +0x7d4

This comment has been minimized.

Copy link

commented Aug 5, 2018

Change mentions this issue: cmd/go: fix panic when go mod tidy an project with no Go file


This comment has been minimized.

Copy link

commented Aug 19, 2018

@agnivade agnivade closed this Aug 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.