bufbuild / buf

The best way of working with Protocol Buffers.
https://buf.build
Apache License 2.0
9.18k stars 278 forks source link

[BUG] go module check update for buf package failed #3453

Closed solarhell closed 1 week ago

solarhell commented 2 weeks ago

How to reproduce

https://sum.golang.org/lookup/buf.build/gen/go/protocolbuffers/wellknowntypes/connectrpc/go@v1.17.0-20240829202630-d59b7d45e69d.1

Output

not found: buf.build/gen/go/protocolbuffers/wellknowntypes/connectrpc/go@v1.17.0-20240829202630-d59b7d45e69d.1: reading https://buf.build/gen/go/buf.build/gen/go/protocolbuffers/wellknowntypes/connectrpc/go/@v/v1.17.0-20240829202630-d59b7d45e69d.1.zip: 400 Bad Request
    server response: generating files: invalid_argument: plugin "buf.build/connectrpc/go:v1.17.0" exited with non-zero status 1: protoc-gen-connect-go: unable to determine Go import path for "google/protobuf/cpp_features.proto"

Expected Output

something like this

https://sum.golang.org/lookup/golang.org/x/tools@v0.26.0

30629555
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=

go.sum database tree
31465925
o2YqmsR/07bA4UH1xIFDEKC/Ue8LQMFM3w/58zAQV6c=

— sum.golang.org Az3grseXe9LdN4DYVxObtPAPFOdsY7pxJHh3CMtSGKHHjcFh4GR1T5xNy2ABLTnswaSo5OyT9RJ/1sv6ah0cooo0zQA=

Anything else?

No response

doriable commented 2 weeks ago

Hello, thanks for filing this issue. This is occurring because we added cpp_features.proto and java_features.proto files which do not have the go package option defined.

That being said, if you are looking to work with well-known types and Go code, they are available already in the Go protobuf runtime: https://pkg.go.dev/google.golang.org/protobuf/types/known@v1.35.1.

I also noted that you are attempting to generate this with connect-go -- there are no RPC services for well-known types, which is what the connect-go plugin is used to generate, so you should not be using the plugin with the well-known type protobuf definitions.

solarhell commented 2 weeks ago

Thanks for the reply, I am indeed using connect-go and have added googleapis and wellknowntypes to the deps of buf.yaml. What should I tweak to avoid generating code for wellknowntypes?

FYI,this my is my current config

buf.yaml

version: v2
modules:
  - path: .
    name: buf.build/wolodata/api
lint:
  use:
    - STANDARD
  except:
    - FIELD_NOT_REQUIRED
    - PACKAGE_NO_IMPORT_CYCLE
  disallow_comment_ignores: true
breaking:
  use:
    - FILE
  except:
    - EXTENSION_NO_DELETE
    - FIELD_SAME_DEFAULT
deps:
    - buf.build/googleapis/googleapis
    - buf.build/protocolbuffers/wellknowntypes

and buf.gen.yaml

version: v2
managed:
  enabled: true
  override:
    - file_option: go_package_prefix
      value: github.com/wolodata/proto/gen
plugins:
  - remote: buf.build/protocolbuffers/go:v1.35.1
    out: gen
    opt:
      - paths=source_relative
  - remote: buf.build/connectrpc/go:v1.17.0
    out: gen
    opt:
      - paths=source_relative
  - remote: buf.build/connectrpc/es:v1.5.0
    out: gen
  - remote: buf.build/bufbuild/es:v1.10.0
    out: gen
doriable commented 2 weeks ago

Ah okay, I see, thank you for providing this context! So if you are using the well-known types as a part of your proto definitions, you don't actually need to provide the buf.build/protocolbuffers/wellknowntypes module, you get them for free as part of the compilation. There is a small quote in the well-known types module documentation on this:

Even without depending on this module, you can use these files out of the box.

So unless you have a special use-case (as outlined in the README), you can simply remove that from your deps. Let me know if this helps! That being said, we are also still looking into the issue with the Go module internally.

solarhell commented 1 week ago

Thanks for you reply.

I tried removing buf.build/protocolbuffers/wellknowntypes from the deps of buf.yaml, and when I run buf lint, the warning suggests that

WARN    File "permission/v1/permission.proto" imports "google/protobuf/descriptor.proto", which is not in your workspace or in the dependencies declared in your buf.yaml, but is found in transitive dependency "buf.build/protocolbuffers/wellknowntypes".
Declare "buf.build/protocolbuffers/wellknowntypes" in the deps key in your buf.yaml.
WARN    File "article/v1/article.proto" imports "google/protobuf/wrappers.proto", which is not in your workspace or in the dependencies declared in your buf.yaml, but is found in transitive dependency "buf.build/protocolbuffers/wellknowntypes".
Declare "buf.build/protocolbuffers/wellknowntypes" in the deps key in your buf.yaml.

And the generated connect-rpc code still requires buf.build/gen/go/protocolbuffers/wellknowntypes/connectrpc/go.

module buf.build/gen/go/wolodata/api/connectrpc/go

go 1.21

require (
    buf.build/gen/go/protocolbuffers/wellknowntypes/connectrpc/go v1.17.0-20240829202630-d59b7d45e69d.1
    buf.build/gen/go/wolodata/api/protocolbuffers/go v1.34.2-20241111085537-48f371483e91.2
    connectrpc.com/connect v1.17.0
)

And check the code, i can see that the buf.build/gen/go/protocolbuffers/wellknowntypes/protocolbuffers/go is not used.

image image
doriable commented 1 week ago

So I did a little digging into your issue by checking your module on buf.build/wolodata/api. Because you added the buf.build/protocolbuffers/wellknowntypes dependency in the past, it is not being pruned from your buf.lock, even though it is removed from your buf.yaml.

In this case, the easiest solution will be to remove your buf.lock entirely and then run buf dep update with your new buf.yaml without the dependency on buf.build/protocolbuffers/wellknowntypes. This will pick up any updates to googleapis, but you are already depending on the latest version. This will now remove your dependency entirely on the well-known types module, and should no longer pick this up in your generated code.

Let me know if this helps!

solarhell commented 1 week ago

After removing buf.lock and updated the deps, it works fine. Thank you for your generous help.