I am receiving error when try to encode Google.Protobuf.Struct.
Example of executed code:
Google.Protobuf.Struct.encode(Google.Protobuf.Struct.new(fields: %{"valid" => {:bool_value, true}}))
Stacktrace:
** (Protobuf.EncodeError) Got error when encoding Google.Protobuf.Struct#fields: %Protobuf.EncodeError{message: "Got error when encoding Google.Protobuf.Struct.FieldsEntry#value: %Protocol.UndefinedError{description: \"\", protocol: Enumerable, value: {:bool_value, true}}"} (elixir) /home/build/elixir/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1 (elixir) /home/build/elixir/lib/elixir/lib/enum.ex:141: Enumerable.reduce/3 (elixir) lib/enum.ex:3015: Enum.reduce/3 (protobuf) lib/protobuf/builder.ex:12: Protobuf.Builder.new/2 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:14: Protobuf.Encoder.encode/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:83: anonymous fn/5 in Protobuf.Encoder.encode_field/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:50: anonymous fn/5 in Protobuf.Encoder.encode!/2 (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:20: Protobuf.Encoder.encode/2 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:83: anonymous fn/5 in Protobuf.Encoder.encode_field/3 (elixir) lib/enum.ex:1331: anonymous fn/3 in Enum.map/2 (stdlib) maps.erl:232: :maps.fold_1/3 (elixir) lib/enum.ex:1956: Enum.map/2 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:50: anonymous fn/5 in Protobuf.Encoder.encode!/2 (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:20: Protobuf.Encoder.encode/
I think that is because nil passed as argument to Protobuf.Encoder.is_enum_default/2 and is_atom(v) guard thinks that it is valid.
I can fix it by adding not is_nil check to function, but I don't know if it is a right way to solve this problem.
I am receiving error when try to encode Google.Protobuf.Struct. Example of executed code:
Google.Protobuf.Struct.encode(Google.Protobuf.Struct.new(fields: %{"valid" => {:bool_value, true}}))
Stacktrace:** (Protobuf.EncodeError) Got error when encoding Google.Protobuf.Struct#fields: %Protobuf.EncodeError{message: "Got error when encoding Google.Protobuf.Struct.FieldsEntry#value: %Protocol.UndefinedError{description: \"\", protocol: Enumerable, value: {:bool_value, true}}"} (elixir) /home/build/elixir/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1 (elixir) /home/build/elixir/lib/elixir/lib/enum.ex:141: Enumerable.reduce/3 (elixir) lib/enum.ex:3015: Enum.reduce/3 (protobuf) lib/protobuf/builder.ex:12: Protobuf.Builder.new/2 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:14: Protobuf.Encoder.encode/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:83: anonymous fn/5 in Protobuf.Encoder.encode_field/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:50: anonymous fn/5 in Protobuf.Encoder.encode!/2 (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:20: Protobuf.Encoder.encode/2 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:83: anonymous fn/5 in Protobuf.Encoder.encode_field/3 (elixir) lib/enum.ex:1331: anonymous fn/3 in Enum.map/2 (stdlib) maps.erl:232: :maps.fold_1/3 (elixir) lib/enum.ex:1956: Enum.map/2 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:50: anonymous fn/5 in Protobuf.Encoder.encode!/2 (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3 (protobuf) deps/protobuf/lib/protobuf/encoder.ex:20: Protobuf.Encoder.encode/
I think that is because nil passed as argument to
Protobuf.Encoder.is_enum_default/2
andis_atom(v)
guard thinks that it is valid. I can fix it by addingnot is_nil
check to function, but I don't know if it is a right way to solve this problem.