elixir-protobuf / protobuf

A pure Elixir implementation of Google Protobuf.
https://hexdocs.pm/protobuf/readme.html
MIT License
823 stars 143 forks source link

protoc-gen-elixir will crash when indent with 4 space #280

Open wingyplus opened 2 years ago

wingyplus commented 2 years ago

From https://github.com/wingyplus/grpc/blob/main/test/support/helloworld.proto. If I change message field by diff below:

diff --git a/test/support/helloworld.proto b/test/support/helloworld.proto
index 0436df6..9bf602a 100644
--- a/test/support/helloworld.proto
+++ b/test/support/helloworld.proto
@@ -11,7 +11,7 @@ service Greeter {

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

 // The response message containing the greetings

The protoc-gen-elixir will crash with output:

** (MatchError) no match of right hand side value: "st"
    (protobuf 0.10.0) lib/protobuf/decoder.ex:70: Protobuf.Decoder.handle_field/5
    (protobuf 0.10.0) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2
    (protobuf 0.10.0) lib/protobuf/decoder.ex:231: Protobuf.Decoder.value_for_field/3
    (protobuf 0.10.0) lib/protobuf/decoder.ex:382: Protobuf.Decoder.update_in_message/3
    (protobuf 0.10.0) lib/protobuf/decoder.ex:176: Protobuf.Decoder.handle_value/6
    (protobuf 0.10.0) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2
    (protobuf 0.10.0) lib/protobuf/decoder.ex:231: Protobuf.Decoder.value_for_field/3
    (protobuf 0.10.0) lib/protobuf/decoder.ex:382: Protobuf.Decoder.update_in_message/3
--elixir_out: protoc-gen-elixir: Plugin failed with status code 1.

I run it on Windows 11 with PowerShell Core.

juliannoble commented 2 years ago

This occurs also in Windows 10 with standard command prompt or pwsh For me it's not strictly based on the indenting. e.g I get the error with 2 indent spaces below, but apparently not 3 or more message HelloRequest { string name= 1; } however, with message HelloReply { string name123456789 = 1; } I get the error seemingly with any number of indents including zero. (but name1 name12 etc are all fine, as are longer strings such as name1234567891234..)

error is:

protoc --elixir_out=./lib protos/greeter2.proto ** (Protobuf.DecodeError) cannot decode binary data, unknown wire type: 7 (protobuf 0.11.0) lib/protobuf/decoder.ex:80: Protobuf.Decoder.handle_field/5 (protobuf 0.11.0) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2 (protobuf 0.11.0) lib/protobuf/decoder.ex:231: Protobuf.Decoder.value_for_field/3 (protobuf 0.11.0) lib/protobuf/decoder.ex:382: Protobuf.Decoder.update_in_message/3 (protobuf 0.11.0) lib/protobuf/decoder.ex:176: Protobuf.Decoder.handle_value/6 (protobuf 0.11.0) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2 (protobuf 0.11.0) lib/protobuf/decoder.ex:231: Protobuf.Decoder.value_for_field/3 (protobuf 0.11.0) lib/protobuf/decoder.ex:382: Protobuf.Decoder.update_in_message/3 --elixir_out: protoc-gen-elixir: Plugin failed with status code 1.

I thought I could work around it by adjusting names or spaces here and there - but in any non-trivial file it becomes too hard to debug because multiple lines can be causing the error so it's a real showstopper.

juliannoble commented 2 years ago

As a workaround for now I'm trying :protox which seems able to compile proto3 files on windows - but there is less info out there on using this library.