C++: Error code and string for <ClientWriter> Write() failures

460 views
Skip to first unread message

Roman Andronov

unread,
Dec 20, 2021, 11:10:03 AM12/20/21
to grpc.io
C++ only: what is the way to extract the needed error code and the corresponding error string from the GRPC library when the <ClientWriter> Write() call fails?

The <ClientWriter> Write() call returns a useless Boolean True/False value.

That Write() call fails - how can the error code, the corresponding error string and the overall Status of the respective Server-side call be retrieved (if, say, it is known that the Server-side code that participates in this Client streaming call fails)?

Thank  you in advance.

Marc Tibout

unread,
Dec 20, 2021, 4:29:23 PM12/20/21
to grpc.io

Have you tried calling <ClientWriter>Finish() to get the gRPC Status after Write() returned false?
Message has been deleted
Message has been deleted
Message has been deleted

Roman Andronov

unread,
Dec 20, 2021, 5:30:16 PM12/20/21
to grpc.io
Thank you - could you please clarify why would I want to call the <ClientWriter>Finish() function? That will surely end this streaming conversation. Will it not? I mean, what if the client is ready to not close this conversation depending on what the server says: if the server says "please adjust the version number of your messages and I will happily proceed" or some such then the client can adjust on the fly and move on, all without closing the stream.

Am I correct in deducing from what you are saying that *the only* way for a streaming client to find out why the Write() call failed is to close this streaming conversation?

Marc Tibout

unread,
Dec 20, 2021, 5:56:00 PM12/20/21
to grpc.io
I think that your deduction is correct. This is the experience I have with ClientReader, once it fails Read(), the stream needs to be terminated as it won't recover.
There is perhaps a way to get some server information with the <ClientWriter>WaitForInitialMetadata(), but otherwise, protocol negotiation would need to occur before the stream get established.

Roman Andronov

unread,
Dec 21, 2021, 10:59:22 AM12/21/21
to grpc.io
Got it, Marc - thank you very much for your time and reply.
Reply all
Reply to author
Forward
0 new messages