buf: `buf breaking` with `.txtpb` files

I have protoc outputting a file descriptor set, with a .txtpb extension. When I use the protoc-gen-buf-breaking plugin, the breaking change detector is able to compare against the file descriptor set as expected. However, when I try to do the same via the CLI:

$ buf breaking --limit-to-input-files --against .../foo.txtpb --path bar.proto

I get:

Failure: could not unmarshal image: proto: syntax error (line 2:1): invalid field name: �

Is this expected?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

I’m not sure, but perhaps you have some other installation issue. If you’re able to provide reproduction steps for us, we’re happy to take a look, but since we’re not able to reproduce this issue, I’m not sure there’s more we can do.

Closing for now, but let us know if you run into other difficulties.

I’ve attempted to create exact end-to-end reproduction steps, but am unable to reproduce the success of this command. If I run:

rm -f image.txtpb
protoc \
  --proto_path=. \
  --include_imports \
  --include_source_info \
  -o image.txtpb \
    buf_example/proto/messages.proto \
    buf_example/proto/interface.proto
protoc \
  --proto_path=. \
  --buf-breaking_out=. \
  '--buf-breaking_opt={"against_input":"image.txtpb","limit_to_input_files":true}' \
    buf_example/proto/messages.proto \
    buf_example/proto/interface.proto

The result is:

could not unmarshal image: proto: syntax error (line 2:1): invalid field name:
--buf-breaking_out: protoc-gen-buf-breaking: Plugin failed with status code 1.

Which is as expected.

Why do I need to supply the against_input field in ‘–buf-breaking_opt={“against_input”:“image.txtpb”,“limit_to_input_files”:true}’ \ when using protoc-gen-buf-breaking then?

Actually I was mistaken - protoc-gen-buf-breaking IS supposed to use image.txtpb for the against input, but uses the result from protoc for the main input. Why image.txtpb is working in your above command I am not sure - you’d need to give us a specific, reproducible example for how you originally created image.txtpb prior to this invocation of protoc. If you are saying that this same invocation of protoc is both creating image.txtpb AND running breaking change detection, then this is invalid - the against input is meant to check against previous imput, and what is likely happening here is that image.txtpb is empty when you are running protoc-gen-buf-breaking. However, without a complete reproducible end-to-end example of the exact commands you are running, including image.txtpb creation, I can’t be sure.

Is it possible for it to output a text format instead

With buf, it’s easy - just buf build -o to a *.txtpb file. With protoc, it’s very complicated, and not worth pursuing for your case - for completeness, you need to do something like protoc -o /dev/stdout path/to/your/file.proto | protoc -I /path/to/google-wkt --decode=google.protobuf.FileDescriptorSet /path/to/google-wkt/google/protobuf/descriptor.proto, but it’s complicated to explain what all of that is.

it seems like if I switch to buf build, I’d need to run protoc … then buf build -o … for buf breaking to work.

You don’t need to use protoc at all with buf. buf build -o is all you need, you don’t need to do any protoc compilation.