Protobuf: JavaScript: repeated enum AssertionError when deserializingBinary

Created on 6 Oct 2018  路  4Comments  路  Source: protocolbuffers/protobuf

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!

javascript

Most helpful comment

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

All 4 comments

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.

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

Related to #1701

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

Was this page helpful?
0 / 5 - 0 ratings