Skip to content

Commit

Permalink
GH2087: log nested aggregate exceptions
Browse files Browse the repository at this point in the history
cake-build#2087

When the exception thrown in a task is actually a nested `AggregateException`, the output log is:

```
An error occurred when executing task 'taskName'.
Error: One or more errors occurred.
	One or more errors occurred.
```

The first occurence of `One or more errors occurred.` is the message of the parent `AggregateException`. The second occurence is the message if the inner exception, which is itself another `AggregateException`.

Here we add a call to `.Flatten()`. This creates a new single instance of `AggregateException` without nesting, so that the last log line will now show the actual inner exception message.

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.aggregateexception.flatten?view=netframework-4.7.2
  • Loading branch information
Timothée Lecomte authored and devlead committed Mar 19, 2019
1 parent e140acb commit 9d5ea25
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Cake/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static int LogException<T>(ICakeLog log, T ex) where T : Exception
var aex = ex as AggregateException;
if (aex != null)
{
foreach (var exception in aex.InnerExceptions)
foreach (var exception in aex.Flatten().InnerExceptions)
{
log.Error("\t{0}", exception.Message);
}
Expand Down

0 comments on commit 9d5ea25

Please sign in to comment.