elixir-protobuf/protobuf

insufficient data decoding field proto_file error

wingyplus opened this issue · 7 comments

From https://github.com/wingyplus/grpc/blob/main/test/support/helloworld.proto. I got an error when I run the command below:

$ protoc --elixir_out=plugins=grpc:. helloworld.proto

Expected

The protoc should generate successfully. And the helloworld.pb.ex should present.

Actual

The protoc-gen-elixir output decode error:

** (Protobuf.DecodeError) insufficient data decoding field proto_file, expected <<10, 17, 104, 101, 108, 108, 111, 119, 111, 114, 108, 100, 50, 46, 112, 114, 111, 116, 111, 18, 10, 104, 101, 108, 108, 111, 119, 111, 114, 108, 100, 34, 34, 10, 12, 72, 101, 108, 108, 111, 82, 101, 113, 117, 101, 115, 116, 18, 18, 10, ...>> to be at least 913 bytes
    (protobuf 0.10.0) lib/protobuf/decoder.ex:164: Protobuf.Decoder.decode_delimited/4
    (protobuf 0.10.0) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2
    (protobuf 0.10.0) lib/protobuf/protoc/cli.ex:47: Protobuf.Protoc.CLI.main/1
    (elixir 1.13.4) lib/kernel/cli.ex:126: anonymous fn/3 in Kernel.CLI.exec_fun/2
--elixir_out: protoc-gen-elixir: Plugin failed with status code 1.

EDIT: I run it on Windows 11 with PowerShell Core.

That file in PR description work on --go_out flag by patch helloworld.proto to:

diff --git a/test/support/helloworld.proto b/test/support/helloworld.proto
index 0436df6..4d66e3a 100644
--- a/test/support/helloworld.proto
+++ b/test/support/helloworld.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";

+option go_package = "github.com/wingyplus/grpc";
+
 package helloworld;

 // The greeting service definition.

And then run protoc --go_out=. .\helloworld.proto

This seems to be a Windows-specific issue. If I run this in the latest main of this repository with the file you provided, it seems to work just fine.

Elixir generated code
syntax = "proto3";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
  rpc CheckHeaders (HeaderRequest) returns (HeaderReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

message HeaderRequest {
}

message HeaderReply {
  string authorization = 1;
}

This can be related to something wrong with the plugin on Windows, so I'll close this issue and bundle it together with #280. Thanks for the report @wingyplus 💟

Thanks :)

I have exactly the same issue, @wingyplus did you manager to solve it ?

** (Protobuf.DecodeError) insufficient data decoding field proto_file, expected <<10, 16, 104, 101, 108, 108, 111, 119, 111, 114, 108, 100, 46, 112, 114, 111, 116, 111, 18, 10, 104, 101, 108, 108, 111, 119, 111, 114, 108, 100, 34, 34, 10, 12, 72, 101, 108, 108, 111, 82, 101, 113, 117, 101, 115, 116, 18, 18, 10, 4, ...>> to be at least 753 bytes
    (protobuf 0.11.0) lib/protobuf/decoder.ex:164: Protobuf.Decoder.decode_delimited/4
    (protobuf 0.11.0) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2
    (protobuf 0.11.0) lib/protobuf/protoc/cli.ex:47: Protobuf.Protoc.CLI.main/1
    (elixir 1.14.0) lib/kernel/cli.ex:131: anonymous fn/3 in Kernel.CLI.exec_fun/2
--elixir_out: protoc-gen-elixir: Plugin failed with status code 1.

Nope. There’s something weird during bytes decoding in Windows. The bytes layout looking a bit different than macOS platform.

@wingyplus so there is not good library that supports grpc for elixir ? (OS agnostic)

It’s hard to say like that. It’s just a bug and the problem is no one has a windows that help investigate and I have not much time to take a look at it.