Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include more detailed exception information when Exception is AggregateException #2087

Closed
richardgavel opened this issue Mar 16, 2018 · 10 comments
Milestone

Comments

@richardgavel
Copy link

I have Tasks that will execute a Parallel.Invoke of an array of Actions. However, when an error happens, all I'll see is the "One or more errors occured". Maybe AggregateExceptions should output the message of each child exception.

@devlead
Copy link
Member

devlead commented Mar 16, 2018

Which version on Cake are you using, have you tried executing Cake with diagnostic verbosity?

@jnm2
Copy link
Contributor

jnm2 commented Mar 16, 2018

If changing the verbosity affects it, I would wonder is it ever helpful to see only the message in the special case of an AggregateException?

@devlead
Copy link
Member

devlead commented Mar 16, 2018

@jnm2 Issue could be that it's already within an aggregate exception because the async support. So could be an extra layer of abstraction. Whereas diagnostic gives the whole stack trace.

@jnm2
Copy link
Contributor

jnm2 commented Mar 16, 2018

@devlead It is an extra layer of abstraction because he is using Parallel.Invoke. I ran into the same thing with Task.WhenAll. It's sort of like if I wrote throw new AggregateException(new InvalidOperationException("foo")). I could be wrong, but wouldn't it be nice if Cake showed the messages of the InnerExceptions collection even when I'm on the default verbosity and not looking for the stack trace?

@devlead
Copy link
Member

devlead commented Mar 16, 2018

Well anything's possible would need to be recursive then I guess. to fetch inner inner exception messages and so on too.

@jnm2
Copy link
Contributor

jnm2 commented Mar 16, 2018

Yes, that's a good idea! It would be like Visual Studio's exception helper window!

throw new AggregateException(
    new AggregateException(
        new InvalidOperationException("hello")));

Makes it show:

image

And here's the middle one:

image

@patriksvensson
Copy link
Member

patriksvensson commented Mar 16, 2018

I wonder if Ben Adams magic exception demystifier exists as a source package... 😄

@jnm2
Copy link
Contributor

jnm2 commented Mar 16, 2018

@Duracell1989
Copy link

Some issue here;
I do multiple validations and combine them in 1 AggregateException.
I don't want the users to: fix 1 validation; re-run; new error; fix; re-run; etc.
That's why I want to combine them in 1 AggregateException and then I just need to throw 1 exception with all the relevant information.

@tlecomte
Copy link

Given that the code already tries to handle AggregateException here, could it be that we are just missing support for nested AggregateExceptions ? Looks like it can be handled with AggregateException.Flatten.

tlecomte pushed a commit to tlecomte/cake that referenced this issue Mar 18, 2019
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
devlead pushed a commit to tlecomte/cake that referenced this issue Mar 19, 2019
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
@devlead devlead added this to the v0.33.0 milestone Mar 19, 2019
@gep13 gep13 closed this as completed Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants