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

Panic when missing go directive in a go.mod #317

Closed
alexandear opened this issue Nov 26, 2024 · 1 comment · Fixed by #318
Closed

Panic when missing go directive in a go.mod #317

alexandear opened this issue Nov 26, 2024 · 1 comment · Fixed by #318

Comments

@alexandear
Copy link
Contributor

gofumpt panics when the go directive is missing in a go.mod file.

For example, we get a panic when trying to run gofumpt on the repo google/uuid (latest v1.6.0), which doesn't have the go directive in it.

❯ go run mvdan.cc/gofumpt@latest -w .
panic: invalid Go version: "go"

goroutine 6 [running]:
mvdan.cc/gofumpt/format.File(0x14000288000, 0x1400029e000, {{0x100348354, 0x2}, {0x140000146a8, 0x16}, 0x0})
        /Users/Oleksandr_Redko/go/pkg/mod/mvdan.cc/[email protected]/format/format.go:99 +0x23c
main.processFile({0x140001ce498, 0x6}, {0x1003f1068, 0x140001da270}, {0x0?, 0x0?}, 0x14000028f20, 0x0)
        /Users/Oleksandr_Redko/go/pkg/mod/mvdan.cc/[email protected]/gofmt.go:313 +0x23c
main.gofmtMain.func4.1(0x0?)
        /Users/Oleksandr_Redko/go/pkg/mod/mvdan.cc/[email protected]/gofmt.go:529 +0x40
main.(*sequencer).Add.func2()
        /Users/Oleksandr_Redko/go/pkg/mod/mvdan.cc/[email protected]/gofmt.go:191 +0x48
created by main.(*sequencer).Add in goroutine 1
        /Users/Oleksandr_Redko/go/pkg/mod/mvdan.cc/[email protected]/gofmt.go:190 +0x1a8
exit status 2

The documentation states, that "If the go directive is missing, go 1.16 is assumed".

@mvdan
Copy link
Owner

mvdan commented Jan 2, 2025

Oops, nice catch. I honestly hadn't run into a module that didn't yet declare a version, given that this has existed for many years by now. I would honestly recommend that the uuid module add the directive, but I agree we need to fix the panic regardless.

@mvdan mvdan closed this as completed in #318 Jan 2, 2025
@mvdan mvdan closed this as completed in 3b99647 Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants