question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Go 1.16

See original GitHub issue

Go 1.16 now rejects empty go.mod files (c.f. https://github.com/golang/go/commit/d4986e0e1d6e03e1b92e905ca5e01b4c223fbeb3). This means that golang hooks cannot be installed anymore:

$ pre-commit install-hooks
[INFO] Initializing environment for local.
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/bin/go', 'get', './...')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    go: no module declaration in go.mod. To specify the module path:
    	go mod edit -module=example.com/mod
    
Check the log at /Users/rdraoui/.cache/pre-commit/pre-commit.log

I could get it to work by changing pre_commit/resources/empty_template_go.mod from an empty file to:

module example/mod

But I’m not all that familiar with how modules work in different Go versions, so maybe making that change has some other implications that I don’t know about. This Go Wiki entry seems to suggest that empty go.mod files are legal, but maybe it’s outdated… (c.f: https://github.com/pre-commit/pre-commit/pull/1428#pullrequestreview-404547009)

The fix is compatible with Go 1.15.

I tried validating the fix by running the test suite (pytest tests -k golang), but I can’t get it to pass with Go 1.15 and current master branch either.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Feb 24, 2021

this is the minimal patch to fix repo: local for golang (as far as I can tell, all other usages of go work already):

$ git diff
diff --git a/pre_commit/resources/empty_template_go.mod b/pre_commit/resources/empty_template_go.mod
index e69de29..fc0ab8c 100644
--- a/pre_commit/resources/empty_template_go.mod
+++ b/pre_commit/resources/empty_template_go.mod
@@ -0,0 +1,3 @@
+go 1.11
+
+module pre-commit-dummy-empty-module

the testsuite however uses classical gopath-based modules which apparently are outright broken by go 1.16 unless GO111MODULE=auto is set (which is outside the control of pre-commit)

0reactions
asottilecommented, Feb 25, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Go 1.16 Release Notes - The Go Programming Language
Go 1.16 adds support of 64-bit ARM architecture on macOS (also known as Apple Silicon) with GOOS=darwin , GOARCH=arm64 . Like the darwin/amd64...
Read more >
Add support for Go 1.16 · Issue #425 · aws/aws-codebuild ...
Ignore the provided versions and install it on our own? We would like to rely on the AWS provided images, for performance and...
Read more >
support Go 1.16 in the Go Playground - Google Groups
all: support Go 1.16 in the Go Playground This makes a number of changes in order to support modules being on by default...
Read more >
go@1.16 - Homebrew Formulae
go @1.16. Install command: brew install go@1.16 ... Formula code: go@1.16.rb on GitHub. Bottle (binary package) installation support provided for: ...
Read more >
IBM Open Enterprise SDK for Go 1.16 : User's Guide
linux', which might need to add zos to the build tag: "+build linux zos" or "+build !linux,!zos". • Look for go.mod file and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found