You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to respond with a google.protobuf.Struct, the call errors with status 13 INTERNAL Error serializing response: Expected argument of type google.protobuf.Struct.
Run it, and try to call getStruct (using Postman, for example).
The server replies with an error: Error serializing response: Expected argument of type google.protobuf.Struct
As we say, things are clearer in the morning! I found out what's my issue.
This error is coming from this check in the compiled proto file:
if(!(arginstanceofgoogle_protobuf_struct_pb.Struct)){thrownewError('Expected argument of type google.protobuf.Struct');}
Now, why this cause issues in my case?
In my project, compiled proto files are put in a separate package that is installed with npm (to prevent code duplication).
Basically:
my repo
|─ server
| |─ package.json
| `─ server.js
`─ lib/testproto
|─ package.json
|─ test.proto
|─ test_grpc_pb.js
`─ test_pb.js
So when in server, I npm I -S ../lib/testproto, npm generates a symlink like this: node_modules/testproto -> ../../lib/cache
Because it's a symlink, module deduplication between server and testproto doesn't work, as shown by npm ls google-protobuf in server:
As such, compiled files in testproto don't use the same files than server when doing require('google-protobuf'), breaking the instanceof check done in the compiled proto file.
In other words, that means that in the server, I generated an instance of Struct coming from:
(while it's the same code in the 2 files, they are different objects for the JS engine)
I'm not sure how to properly fix this issue. We can't even check arg.constructor.name because Struct isn't a class, but an anonymous function.
Right now I have a workaround by using TestService.getStruct.responseType.fromJavaScript(myObj) instead of Struct.fromJavaScript(myObj), but that's a hacky solution I don't like at all!
Problem description
When trying to respond with a
google.protobuf.Struct
, the call errors with status 13 INTERNALError serializing response: Expected argument of type google.protobuf.Struct
.Reproduction steps
Use this proto file:
Compile it with:
Then create the following server:
Run it, and try to call
getStruct
(using Postman, for example).The server replies with an error:
Error serializing response: Expected argument of type google.protobuf.Struct
I also tried with a plain object:
I get the same error.
Maybe I'm missing something obvious, but I've been trying a lot of things for the past hours and I still can't figure how to send a Struct...
Environment
The text was updated successfully, but these errors were encountered: