Ex_protobuf not parsing proto file

Hello,

Trying to use the exprotobuf library, but get the following error message:

defmodule Messages do
  use Protobuf,
    from: Path.expand("/home/wannes/Documents/ex_cucumber_message/messages.proto")

  # use_package_names: true,
  # namespace: :"Elixir"
end

> $ mix compile                                                                                         
Compiling 1 file (.ex)

== Compilation error in file lib/cucumber_messages/messages.ex ==
** (CaseClauseError) no case clause matching: %Protobuf.Field{fnum: 1, name: :name, occurrence: :defaulty, opts: [], rnum: 2, type: :string}
    lib/exprotobuf/define_message.ex:147: Protobuf.DefineMessage.define_trivial_typespec_fields/2
    lib/exprotobuf/define_message.ex:135: Protobuf.DefineMessage.define_trivial_typespec/1
    lib/exprotobuf/define_message.ex:54: Protobuf.DefineMessage.def_message/3
    lib/exprotobuf/builder.ex:135: anonymous fn/6 in Protobuf.Builder.generate/2
    (elixir 1.10.3) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/exprotobuf/builder.ex:82: Protobuf.Builder.generate/2
    (stdlib 3.13) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib 3.13) erl_eval.erl:449: :erl_eval.expr/5

I’ve put the code at : https://github.com/WannesFransen1994/ex_cucumber_messages . The proto file is messages.proto .

Note: The proto file can be parsed with the ahamez/protox library, which appears to be more performant but does require compile-time external dependencies. Hence my slight personal preference to exprotobuf, if it compiles.

Thank you in advance.

Just out of the interest - why not use Elixir-native implementations of Gherkin parser and/or full Cucumber-like BDD testing libraries? For example there is mine Watermelon library.

1 Like

Thank you for your blazing fast response! I’ve only seen cabbage and whitebread tbh. The problem was that either it wasn’t fully compliant with the gherkin syntax/standards / testdata / features, or had bugs / missing implementations.

Hence the effort to try to go into the cucumber monorepo. (using their testdata, also with the berp parser etc…) This seemed us more manageable. Feel free to check my progress at https://github.com/WannesFransen1994/ex_gherkin and honestly help would be so much appreciated!

Or am i completely wrong here? ^^’

Oh forgot to say this, but instead of holding a complete conversation on elixir forum (if you want to ask more direct questions), feel free to hit me up on the Elixir slack (username WFrans).

I found your thread while googling for a similar error that was happening in my codebase, it seems that the latest version of gpb changed its internal structure and ExProtobuf does not support it yet.

I’ve opened an issue and a PR

If you want a quick fix you could probably just add

...
{:gpb, "~> 4.12.0"}
...

to your mix.exs

You can check out mine library, and if something is missing, then you can open an issue and I will look into it as soon as I will find time. Probably Background do not work right now, but the question is whether it should be treated as setup_all or setup.

Thank you for your reaction. I’ve tried both adding the dependency and compiling with your PR branch, but both fail. The error message changed a little bit though:

== Compilation error in file lib/cucumber_messages/messages.ex ==
** (CaseClauseError) no case clause matching: 2
    lib/exprotobuf/define_message.ex:147: Protobuf.DefineMessage.define_trivial_typespec_fields/2
    lib/exprotobuf/define_message.ex:135: Protobuf.DefineMessage.define_trivial_typespec/1
    lib/exprotobuf/define_message.ex:54: Protobuf.DefineMessage.def_message/3
    lib/exprotobuf/builder.ex:135: anonymous fn/6 in Protobuf.Builder.generate/2
    (elixir 1.10.3) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/exprotobuf/builder.ex:82: Protobuf.Builder.generate/2
    (stdlib 3.13) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib 3.13) erl_eval.erl:449: :erl_eval.expr/5