question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aggregate exceptions

See original GitHub issue

Great library! Biggest problem with doing good work is people raise awkward questions! Sorry.

What’s the best way to handle AggregateExceptions? I’m using Service Fabric and Serilog for all my logging. Lots of cross service exceptions are exposed as AggregateExceptions and they still produce a generally old fashioned stack trace.

I’ve got something working by just logging the inner exception, but that seems like I’m handling the problem at the wrong level. I think Demystify should handle the aggregate exception internally.

This change in Demystify may work - does it make sense?

                if (exception is AggregateException aex)
                {
                    foreach (var innerException in aex.InnerExceptions)
                    {
                        innerException.Demystify();
                    }
                }
                else
                {
                    exception.InnerException?.Demystify();
                }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nrandellcommented, Nov 13, 2017

Much better - thanks for the quick response! Wish I had this a few years ago.

System.OperationCanceledException: Aborted ---> Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unexpected end of request content.
   at void Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeCompletion.ThrowFailed()
   at void Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.GetResult(ref ReadResult result)
   at ReadResult Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IReadableBufferAwaiter.GetResult()
   at async Task<int> Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.ReadAsync(ArraySegment<byte> buffer, CancellationToken cancellationToken)
   at async Task<int> Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestStream.ReadAsyncInternal(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
   at async Task System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(int minimumRequiredBytes, CancellationToken cancellationToken, bool throwOnPrematureClosure)
   at async Task<WebSocketReceiveResult> System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate(ArraySegment<byte> payloadBuffer, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at async Task<WebSocketReceiveResult> System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate(ArraySegment<byte> payloadBuffer, CancellationToken cancellationToken)
   at async Task PlatformWebApi.Sockets.WebSocketConnection.RunAsync() in C:\Users\nick\Source\Repos\SceneSkopePlatform\PlatformWebApi\Sockets\WebSocketConnection.cs:line 56
   at async Task PlatformWebApi.Startup.RunWebSocketAsync(WebSocket webSocket, HttpContext context) in C:\Users\nick\Source\Repos\SceneSkopePlatform\PlatformWebApi\Startup.cs:line 87
   at async Task PlatformWebApi.Sockets.WebSocketHandler.AcceptAsync(HttpContext context) in C:\Users\nick\Source\Repos\SceneSkopePlatform\PlatformWebApi\Sockets\WebSocketHandler.cs:line 29
   at async Task Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)
   at async Task Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
   at async Task PlatformWebApi.SerilogMiddleware.Invoke(HttpContext httpContext) in C:\Users\nick\Source\Repos\SceneSkopePlatform\PlatformWebApi\SerilogMiddleware.cs:line 37
   at async Task Microsoft.ServiceFabric.Services.Communication.AspNetCore.ServiceFabricMiddleware.Invoke(HttpContext context)
   at async Task Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.Invoke(HttpContext httpContext)
   at async Task Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame<TContext>.ProcessRequestsAsync()
1reaction
benaadamscommented, Nov 13, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

exception - AggregateException C# example
AggregateException is often used for catching exceptions, that might occur when waiting for a Task to complete. Because Task in general can ...
Read more >
How to Throw Multiple Exceptions at Once, Using ...
An aggregate exception therefore, is an single exception that is composed of multiple separate exceptions. How do I create an aggregate ...
Read more >
AggregateException.Flatten Method (System)
Flatten method to rethrow the inner exceptions from multiple AggregateException instances thrown by multiple tasks in a single AggregateException instance, as ...
Read more >
Debugging System.AggregateException - even in async code
As the name implies, AggregateException is used to batch one or more exceptions together in a single exception. In this post, I'll show...
Read more >
How to fix unhandled AggregateException - YouTube
This video explains why AggregateException catch block never reached when Exception is raised during Tasks execution ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found