How to Unwrap an AggregateException Thrown by #aws #lambda
▻https://hackernoon.com/how-to-unwrap-an-aggregateexception-thrown-by-aws-lambda-6652fd085952?so
If you’ve written a .NET Lambda function which calls async code and returns either Task or Task<T>, you’ve probably seen an AggregateException which wraps the real exception.This example comes from the handler below which calls an asnyc method that always throws a FormatException.The AggregateException can be unwrapped, though. When AWS added .NET Core 2.1 support to Lambda, they also added an undocumented feature toggle. The only real mention of it is by the AWS .NET team on Reddit.When the UNWRAP_AGGREGATE_EXCEPTIONS environment variable is set to 1 or true, Lambda will call GetAwaiter().GetResult() instead of using theResult property.Note that this only works if your method returns Task or Task<T>.This causes the first exception thrown to be returned instead of an (...)