Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript: repeated enum AssertionError when deserializingBinary #63

Open
shtengel opened this issue Oct 6, 2018 · 6 comments
Open
Labels
bug Something isn't working javascript port-fix triaged Issue has been triaged

Comments

@shtengel
Copy link

shtengel commented Oct 6, 2018

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!

@TeBoring TeBoring self-assigned this Oct 7, 2018
@TBoshoven
Copy link

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.

@solidfox
Copy link

solidfox commented Jul 8, 2019

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

@kellycampbell
Copy link

Related to protocolbuffers/protobuf#1701

@smnbbrv
Copy link

smnbbrv commented Feb 12, 2020

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

@acozzette acozzette transferred this issue from protocolbuffers/protobuf May 16, 2022
@dibenede dibenede added bug Something isn't working triaged Issue has been triaged port-fix labels Sep 23, 2022
@dibenede
Copy link
Contributor

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

@lukesandberg
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working javascript port-fix triaged Issue has been triaged
Projects
None yet
Development

No branches or pull requests

8 participants