bitwalker / bitwalker/exprotobuf

Decoding not existing oneof field should return an error

Open
#94 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
482
Forks
68
PR merge metrics
No merged PRs in 30d

Description

When decoding a message using a oneof with a field that has not been defined by the code doing the decoding, no error is thrown. Instead, the field has the `nil` value. It would be better if the decode function would fail with an explicit error instead of giving an invalid result.

Example:

`one_of.proto`

```

message SampleOneofMsg {
optional string one = 1;

oneof foo {
string body = 3;
uint32 code = 4;
}
}

message SampleOneofExtMsg {
optional string one = 1;

oneof foo {
string body = 3;
uint32 code = 4;
string meta = 5;
}
}

```

This code:
```
msg_ext = Msgs.SampleOneofExtMsg.new(foo: {:meta, "meta"}, one: "test")
enc_msg = Protobuf.Serializable.serialize(msg_ext)

IO.inspect(Msgs.SampleOneofMsg.decode(enc_msg))
```

will return:

```
%Protobuf.Oneof.Test.Msgs.SampleOneofMsg{foo: nil, one: "test"}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with one_of.proto using Protobuf.Serializable.serialize and Msgs.SampleOneofMsg.decode, where the encoded message contains the undefined meta oneof field. Trace the oneof decoding path and determine how unknown fields are handled; done means decoding returns an explicit error instead of a message with foo: nil.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.