exprotobuf icon indicating copy to clipboard operation
exprotobuf copied to clipboard

Run verify_msg before encoding

Open luisguilhermemsalmeida opened this issue 2 years ago • 1 comments

Encoding integer values of out the specified range (overflow) results in an invalid binary which crashes the decoding in a way that is very hard to troubleshoot. It's best if the encoding fails with an easy message:

** (ErlangError) Erlang error: {:gpb_type_error, {{:value_out_of_range, :unsigned, 32}, [value: 340282366920938463463374607431768211456, path: 'path_to_the_invalid_field']}}

https://github.com/tomas-abrahamsson/gpb README file states:

Gpb can optionally generate code for verification of values during encoding this makes it easy to catch e.g integers out of range, or values of the wrong type.

luisguilhermemsalmeida avatar Feb 22 '23 13:02 luisguilhermemsalmeida

@bitwalker Did you have the time to take a look at this PR? Thanks!

luisguilhermemsalmeida avatar Apr 26 '23 12:04 luisguilhermemsalmeida