Your gRPC Error Carries a Second Trailer the Node Client Never Reads

A gRPC call that fails hands you an error code and a message, and that is the whole of what most clients will ever tell you. The protocol has a second trailer for the long version: grpc-status-details-bin, carrying a google.rpc.Status with the same code and message plus a list of Any details, stack traces, help links, request ids. I stood up a Node server on grpc-js 1.14.6 that fails a call with exactly that: UNAVAILABLE, message upstream flaky, and three details, a DebugInfo with two stack frames, a Help with a link, and a RequestInfo with an id. The Status encodes to 203 bytes. The wire carries those 203 bytes base64-encoded, 272 characters of ASCII, in the trailer. You can read the failed call's trailer anatomy in the failed-call post, and the Any inside is walked in the Any post.

Here is the part that cost me a morning: the JavaScript client never reads it. The error I get back has code 14, the message reads 14 UNAVAILABLE: upstream flaky, and err.details holds the message half of that, upstream flaky, nothing else. The trailer is sitting right there in the error, as a raw buffer under grpc-status-details-bin, and the client has not parsed it, not unwrapped the base64, not decoded the Status, not even checked that the content is base64 at all. The spec calls for this trailer and for clients to use it, and the other language clients do parse it into structured error details, but grpc-js at 1.14.6 stops at carrying the bytes. If you want the stack trace your Go service is sending, you have to take the trailer, base64-decode it, and decode it yourself.

So I did, against the vendored protobuf engine, the same one the decode tab at proto.datajutsu.com runs. Base64-decode the trailer, 203 bytes of Status, decode it with code and message and the details list. The interesting behavior is in the details. Each detail is an Any, a type_url and a bag of bytes, and the engine does something you do not expect: when the type named by the type_url is in your schema, it decodes the bag and inlines the fields next to an @type key. My DebugInfo prints with stack_entries as a real two-string array and @type set to type.googleapis.com/google.rpc.DebugInfo. The link inside the Help detail prints as a real object. It reads like the engine understood the whole error. Now put a detail in with a type_url no schema defines, and the same detail prints with its value as an opaque base64 string, no inlining, no error. The engine is not smarter than your schema; it is just as smart.

That last fact is the one that decides what your tool does. The engine inlines Any values only for types it can resolve, and which types it can resolve is the schema you handed it. I ran the same 203 bytes two ways: against a schema with the full google.rpc definitions, and against a file with only google.rpc.Status and the Any definition, no error_details. First run, details inline with @type. Second run, every detail is type_url plus an opaque bytes value, the same shape the client never got past. Same bytes, same decoder, two different answers, and the difference is which .proto files are in scope. If you are building a decoder for gRPC error trailers, the schema question is not an edge case, it is the whole feature.

Three more things I measured that you will hit. The trailer costs real bytes: base64 inflates 203 to 272, a 1.34 multiplier on top of whatever the details already cost, and the details of a production error, a full stack trace, are rarely small. The client does not validate the trailer, I sent a failure whose details-bin was the literal string not-base64-garbage and the call failed normally with the server's code, the junk carried along unexamined, so a broken trailer degrades to no details rather than to an error. And the success path is asymmetric: a server can attach the details trailer to a call that succeeds, the wire carries it in the trailers, and the standard callback never shows it to you because there is no error object to carry it. The long error is a failure-only story in the Node client, whatever the wire says.

So the rules, all measured against grpc-js 1.14.6 and the tool's own engine: the detailed error rides in the grpc-status-details-bin trailer as base64 of a google.rpc.Status; the Node client carries that trailer to you unparsed, in the error's metadata, and leaves err.details as the plain message string; the base64-decoded Status decodes fine, and its Any details inline with @type only for types present in the schema you give the decoder, everything else stays an opaque byte string; the trailer inflates the payload by a third and is never validated, and on a success the Node callback drops it. You can run your own error through it in the decode tab at proto.datajutsu.com: base64-decode the trailer, paste the Status bytes, and paste status.proto with the detail types you care about to see which details open up and which stay closed. The JSON behavior underneath is in the JSON mapping post.

Subscribe to Data Jutsu

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe