public static RpcException Decorate(RpcException exception) { var metadata = new Metadata(); foreach (var trailer in exception.Trailers) { metadata.Add(trailer); } var detailBytes = ((IRpcExceptionDetail)exception).DetailBytes(); var length = detailBytes.Length; if (length < ChunkSize) { metadata.Add(DetailKey, detailBytes); } else { // Hopefully this will never get used. int i = 0; foreach (var chunk in LargeArray.Chunk(detailBytes, ChunkSize)) { var key = string.Format(DetailChunkKey, i); metadata.Add(key, chunk); i++; } metadata.Add(DetailChunkCount, i.ToString()); } metadata.Add(DetailKey, ((IRpcExceptionDetail)exception).DetailBytes()); throw new RpcException(exception.Status, metadata, exception.Message); }
public static bool Build(RpcException baseException, [NotNullWhen(true)] out RpcException?exception) { var trailers = baseException.Trailers; var detail = trailers.GetValueBytes(TypedExceptionInterceptor.DetailKey); if (!(detail is null)) { return(TryBuild(baseException, detail, out exception)); } var detailChunkCountStr = trailers.GetValue(TypedExceptionInterceptor.DetailChunkCount); if (!(detailChunkCountStr is null) && int.TryParse(detailChunkCountStr, out int detailChunkCount)) { var chunks = new List <byte[]>(detailChunkCount); for (int i = 0; i < detailChunkCount; i++) { var key = string.Format(TypedExceptionInterceptor.DetailChunkKey, i); var chunk = trailers.GetValueBytes(key); if (chunk is null) { exception = default; return(false); } chunks.Add(chunk); } detail = LargeArray.Combine(chunks); return(TryBuild(baseException, detail, out exception)); } exception = default; return(false); }