protobuf-javascript icon indicating copy to clipboard operation
protobuf-javascript copied to clipboard

JavaScript: repeated enum AssertionError when deserializingBinary

Open shtengel opened this issue 7 years ago • 6 comments

What version of protobuf and what language are you using? Version: v3.6.1 Language: Javascript with Typescript

What operating system (Linux, Windows, ...) and version? Windows 10 x64

What runtime / compiler are you using (e.g., python version or gcc version) im using tsc (Typescript compiler) In order to generate the .ts files from the .proto im using the command protoc --plugin option with the protoc-gen-ts plugin

What did you do? Steps to reproduce the behavior:

  1. create a protobuf file that contains a repeated enum message
  2. Send a Protobuf binary from my Android App to my Nodejs Express Server
  3. Attempt to deserialize the buffer in my Express Server

What did you expect to see a Protobuf Object

What did you see instead? AssertionError on the repeated enum field.

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs). my custom repeated enum field is repeated Amenities amenities = 22; and another one at =23;

my protobuff buffer base64 encoded: ChoyMDE4LTEwLTA2VDIwOjM5OjI0LjI2NDAyORDcCxgCIAEq8gEKA0dhbBIIU2h0ZW5nZWwangFodHRwczovL3Njb250ZW50LmZzZHYzLTEuZm5hLmZiY2RuLm5ldC92L3QzMS4wLTgvMjYyMjEwMTZfMjA5NzUwMzIwNjk0NTg0Nl82NDE3NzA1NTMyMzI5NDYzMDcyX28uanBnP19uY19jYXQ9MCZvaD1iMjE4Y2ZiNDE2MTFlMWY4YTJjZDA0ODM1MzZjZGI0OCZvZT01QzA5MEFCNCAYggE9SGkgaW0gR2FsLCAyNCBsaWtlcyBhIGxvdCBvZiBzdHVmZiBsaWtlIEZsdXV0dGVyIGFuZCBNb3JlZWVlLjIkMDg3ZWQwM2EtMzJmMS00ZDljLWE1YWEtODQ5Y2U3NDliNWQ1QkkKFteq15wg15DXkdeZ15EgLSDXmdek15USGdep15PXqNeV16og16jXldeY16nXmdec15MaAjU2MVbozfKGCEBAOTaVoBqKY0FAUANYAYIBGjIwMTgtMTAtMDZUMjA6Mzk6MjQuMjY0MjMziAEykAEBmAEEoAEAqgElIEdvb2QgbmV3IGFwYXJ0bWVudCB0byBqb2luIHRvbyAhISEgIbABA7ABArgBAbgBArgBAMABEsgBJNABAA==

my error: [TypeScript] AssertionError: Assertion failed [TypeScript] at new goog.asserts.AssertionError (C:\Users\Gal\Desktop\roommiesusersmicroservice\node_modules\google-protobuf\google-protobuf.js:98:603) [TypeScript] at Object.goog.asserts.doAssertFailure_ (C:\Users\Gal\Desktop\roommiesusersmicroservice\node_modules\google-protobuf\google-protobuf.js:99:126) [TypeScript] at Object.goog.asserts.assert (C:\Users\Gal\Desktop\roommiesusersmicroservice\node_modules\google-protobuf\google-protobuf.js:99:385) [TypeScript] at jspb.BinaryReader.readPackedField_ (C:\Users\Gal\Desktop\roommiesusersmicroservice\node_modules\google-protobuf\google-protobuf.js:359:71) [TypeScript] at jspb.BinaryReader.readPackedEnum (C:\Users\Gal\Desktop\roommiesusersmicroservice\node_modules\google-protobuf\google-protobuf.js:364:287) [TypeScript] at Function.proto.ProtobufApartment.deserializeBinaryFromReader (C:\Users\Gal\Desktop\roommiesusersmicroservice\dist\protobuf\generated\apartment_pb.js:210:67) [TypeScript] at Function.proto.ProtobufApartment.deserializeBinary (C:\Users\Gal\Desktop\roommiesusersmicroservice\dist\protobuf\generated\apartment_pb.js:116:34)

Anything else we should know about your project / environment It crashes when it tries to read my repeated enum field.

please help me.. thanks!

shtengel avatar Oct 06 '18 21:10 shtengel

I seem to be getting the exact same issue when using gRPC-Web (CommonJS). Only workaround I could find is not to use repeated enums.

TBoshoven avatar Feb 04 '19 23:02 TBoshoven

Just ran into this bug and we solved it by wrapping the enum in a wrapped message but I just noticed that an alternative workaround may be to use [packed=false] on the repeated enum. That should use different code. https://developers.google.com/protocol-buffers/docs/proto#specifying-field-rules

solidfox avatar Jul 08 '19 07:07 solidfox

Related to protocolbuffers/protobuf#1701

kellycampbell avatar Aug 17 '19 04:08 kellycampbell

@solidfox thanks, you saved my day! The [packed=false] thing works

smnbbrv avatar Feb 12 '20 11:02 smnbbrv

We didn't use to support this correctly. Our parsing code did not support receiving either option and instead only went by the annotation.

dibenede avatar Sep 23 '22 22:09 dibenede

this will require modifying to code generator to allow for either format on the wire and our BinaryReader to add helpers for 'packable' fields

lukesandberg avatar Sep 23 '22 22:09 lukesandberg