bufbuild / buf

The best way of working with Protocol Buffers.

Home Page:https://buf.build

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

language_version not specified in .pre-commit-hooks.yaml

MustansirS opened this issue · comments

I previously had go@1.19 installed on my system. Since golang version 1.19 is no longer supported and buf requires golang 1.20 I was getting this error when running pre-commit hooks:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/main.py", line 417, in main
    return run(args.config, store, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/commands/run.py", line 442, in run
    install_hook_envs(to_install, store)
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/repository.py", line 240, in install_hook_envs
    _hook_install(hook)
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/repository.py", line 96, in _hook_install
    lang.install_environment(
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/languages/golang.py", line 159, in install_environment
    lang_base.setup_cmd(prefix, ('go', 'install', './...'), env=env)
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/lang_base.py", line 86, in setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/util.py", line 111, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/opt/homebrew/opt/go@1.19/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading go.uber.org/multierr v1.11.0
    go: downloading github.com/bufbuild/protocompile v0.9.0
    go: downloading connectrpc.com/connect v1.15.0
    go: downloading go.uber.org/zap v1.27.0
    go: downloading golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
    go: downloading connectrpc.com/otelconnect v0.7.0
    go: downloading go.uber.org/atomic v1.11.0
    go: downloading google.golang.org/protobuf v1.33.0
    go: downloading github.com/spf13/pflag v1.0.5
    go: downloading golang.org/x/term v0.18.0
    go: downloading go.opentelemetry.io/otel v1.24.0
    go: downloading github.com/stretchr/testify v1.9.0
    go: downloading go.opentelemetry.io/otel/trace v1.24.0
    go: downloading github.com/klauspost/compress v1.17.7
    go: downloading github.com/klauspost/pgzip v1.2.6
    go: downloading github.com/spf13/cobra v1.8.0
    go: downloading github.com/google/go-containerregistry v0.19.0
    go: downloading golang.org/x/net v0.22.0
    go: downloading github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
    go: downloading golang.org/x/crypto v0.21.0
    go: downloading buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240221180331-f05a6f4403ce.1
    go: downloading gopkg.in/yaml.v3 v3.0.1
    go: downloading github.com/bufbuild/protovalidate-go v0.6.0
    go: downloading golang.org/x/tools v0.19.0
    go: downloading github.com/google/cel-go v0.20.1
    go: downloading golang.org/x/mod v0.16.0
    go: downloading github.com/docker/docker v25.0.4+incompatible
    go: downloading github.com/rs/cors v1.10.1
    go: downloading github.com/pkg/profile v1.7.0
    go: downloading github.com/gofrs/flock v0.8.1
    go: downloading github.com/jdx/go-netrc v1.0.0
    go: downloading github.com/bufbuild/protoyaml-go v0.1.8
    go: downloading go.opentelemetry.io/otel/sdk v1.24.0
    go: downloading github.com/google/go-cmp v0.6.0
    go: downloading github.com/go-chi/chi/v5 v5.0.12
    go: downloading github.com/gofrs/uuid/v5 v5.0.0
    go: downloading golang.org/x/sync v0.6.0
    go: downloading go.opentelemetry.io/otel/metric v1.24.0
    go: downloading golang.org/x/sys v0.18.0
    go: downloading github.com/davecgh/go-spew v1.1.1
    go: downloading github.com/pmezard/go-difflib v1.0.0
    go: downloading github.com/go-logr/logr v1.4.1
    go: downloading github.com/docker/cli v25.0.4+incompatible
    go: downloading github.com/mitchellh/go-homedir v1.1.0
    go: downloading github.com/opencontainers/go-digest v1.0.0
    go: downloading github.com/docker/distribution v2.8.3+incompatible
    go: downloading google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8
    go: downloading github.com/stoewer/go-strcase v1.3.0
    go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.3
    go: downloading github.com/felixge/fgprof v0.9.4
    go: downloading github.com/docker/go-connections v0.5.0
    go: downloading github.com/docker/go-units v0.5.0
    go: downloading github.com/moby/term v0.5.0
    go: downloading github.com/morikuni/aec v1.0.0
    go: downloading github.com/distribution/reference v0.5.0
    go: downloading github.com/opencontainers/image-spec v1.1.0
    go: downloading github.com/pkg/errors v0.9.1
    go: downloading go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
    go: downloading github.com/go-logr/stdr v1.2.2
    go: downloading golang.org/x/text v0.14.0
    go: downloading github.com/antlr4-go/antlr/v4 v4.13.0
    go: downloading github.com/sirupsen/logrus v1.9.3
    go: downloading google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8
    go: downloading github.com/russross/blackfriday/v2 v2.1.0
    go: downloading github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7
    go: downloading github.com/containerd/stargz-snapshotter/estargz v0.15.1
    go: downloading github.com/felixge/httpsnoop v1.0.4
    go: downloading github.com/docker/docker-credential-helpers v0.8.1
    go: downloading github.com/gogo/protobuf v1.3.2
    go: downloading github.com/vbatts/tar-split v0.11.5
    # github.com/bufbuild/buf/private/buf/bufcli
    private/buf/bufcli/errors.go:218:21: undefined: tls.CertificateVerificationError
    note: module requires Go 1.20

After investigating pre-commit's own codebase, whats going on here is that since language_version is not specified it gets set either to system if you have golang installed on your system (which was the case for me), or default in which case it installs the latest go version.

Since buf has deprecated use of golang 1.19 I would suggest specifying the language_version in .pre-commit-hooks.yaml to satisfy the dependency

I tried to create a PR to fix this issue but I couldn't push to a branch I made. Are open source contributions not allowed?

Having the same issue! We could specify language_version in our own .pre-commit-hooks.yaml but it is not ideal to have that set on our end, because if there is a future update that breaks buf then we will have to update language_version on our end.

I tried to create a PR to fix this issue but I couldn't push to a branch I made. Are open source contributions not allowed?

Like all OSS projects, to make a PR, you need to create a fork.